In my application I am using facebook accesstoken to post a message to users fan page wall. Now while posting am getting an error like
Malformed access token
I am able to read the posts from fan page wall. But I cant post to wall. I am using 'Curl' to post.
Here is my code:
<!-- language: lang-php -->
$post_url = 'https://graph.facebook.com/pageid/feed';
$data['access_token'] = 'XYZXYZXYZXYZXYZXYZXYZ ';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($ch);
curl_close($ch);
Check if your database doesn't cutoff the access_token string when saved.
I had this problem with facebook once. Are you using a varchar(xx)?
Related
I just want to get the authorization code to obtain the access token to make API requests, I did the step manaully through the pasting the link in the browser and it works.
but through Curl PHP doesn't work I get empty string of size 1400 char.
this's the sample on Quickbooks API doc
curl -X POST 'https://appcenter.intuit.com/connect/oauth2?
client_id=Q3ylJatCvnkYqVKLmkxxxxxxxxxxxxxxxkYB36b5mws7HkKUEv9aI&response_type=code&
scope=com.intuit.quickbooks.accounting&
redirect_uri=https://www.mydemoapp.com/oauth-redirect&
state=security_token%3D138r5719ru3e1%26url%3Dhttps://www.mydemoapp.com/oauth-redirect'
Quickbooks API Auth code ref
I Turned to Curl PHP with replacing my credentials, when I visit the link I get the auth code and I could obtian the access token but can't do it in the back-end
the dir of the page that I want to get the auth code in is https://roifelawgroup.com/clientform/login/info_submit.php
but the redirect link just : https://roifelawgroup.com/ with login creds is this could be the problem?
However I tried with the same page redirect link didn't work
function authcode(){
$url = "https://appcenter.intuit.com/connect/oauth2?client_id=ABfQBA8VYPPUETO5isi2v8p39lQwEsw1ozL7NhZxxxxxx&response_type=code&scope=com.intuit.quickbooks.payment&redirect_uri=https://roifelawgroup.com&state=security_token%3D138r5719ru3e1%26url%3Dhttps://roifelawgroup.com";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // if removed this line I get 301 permanently moved
$headers = array(
"Content-Length: 0",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
}
I am having hard time publishing external image to post. I am using PHP language and curl. I would like to post image (e.g. https://cdn.pixabay.com/photo/2015/06/19/17/58/sample-815141_1280.jpg) to facebook, but the only thing which get's posted is message without any image.
The problem with using photo api is that the post is posted as a picture and not as a post containing image. How can I accomplish this? I also tried with official PHP SDK but so far no luck.
$data['message'] = $_POST["content"];
$data['access_token'] = $page_access_token;
$post_url = 'https://graph.facebook.com/'.$page_id.'/feed';
if($_POST["picture"]!==""){
$data_post['url']=$_POST["picture"];
}
if($_POST["content"]!=="")
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($ch);
curl_close($ch);
}
I have the following code to delete a YouTube video using cURL. I'm getting a 401 response/authorization error. I've put in the API key in the url and do I put the access token in the bearer value in CURLOPT_HTTPHEADER area?
$url = "https://www.googleapis.com/youtube/v3/videos?id=VIDEO_ID_HERE&key=KEY_HERE";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-type: application/json','Authorization : Bearer '.$_SESSION['access_token']));
$result = curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
Are there any other mistakes I'm making?
Okay I had another question on the same topic (deleting videos) so I'll post that answer here now that I've figured it out in case someone finds this via Google. I never figured out the cURL method but the method using the google PHP library for v3 of their API is as follows:
$youtube = new Google_Service_YouTube($client);
...
//do your authoraisation stuff + getting access token etc
...
$youtube->videos->delete('<Your Video ID>');
Hope that helps!
I am new to curl. I'm trying basic authentication using curl with pivotal tracker
error:{"error":"Needs authentication credentials.","possible_fix":"Try basic auth, or include header X-TrackerToken.","code":"unauthenticated","kind":"error".
here is simple code i used to authenticate:
$ch = curl_init();
$data = array('$token'=>'858e234da*****');
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://www.pivotaltracker.com/services/v5/me");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// grab URL and pass it to the browser
$response =curl_exec($ch);
var_dump($response);
// close cURL resource, and free up system resources
curl_close($ch);
how to authenticate my application with token as pivotal tracker support simple ouath authentication.
i would like to explain steps of authentication
a.)user enter user name and password.
b.)then enter token of your profile.
c.) now page is redirected your dashboard.
Try basic auth, or include header X-TrackerToken.
Which seems to me is asking you to submit the token as a X-TrackerToken header.
You can try something like this, though I can't find the pivotaltracker documentation.
$ch = curl_init('https://www.pivotaltracker.com/services/v5/me');
// or just remove the customrequest too
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-TrackerToken: 858e234da*****'
);
$result = curl_exec($ch);
curl_close($ch);
update
Found the documentation.
It shows something like:
export TOKEN='your Pivotal Tracker API token'
curl -X GET -H "X-TrackerToken: $TOKEN" "https://www.pivotaltracker.com/services/edge/stories/558"
I have a Facebook app, where I want to delete some pictures. I have the pictureid and access_token, and have tried every methods I have found on this site, but I get errors every time.
How can this be deleted with CURL? I've started with this:
$ch = curl_init();
$url = 'https://graph.facebook.com/'.$uid.'/photos?access_token='.$access_token;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
echo $data = curl_exec($ch);
Applications can now delete Photos - created by that application.
I tried it with a photo uploaded to a page and deleted it with its id via the Graph API Explorer
The curl url would be:
https://graph.facebook.com/'.$imageId.'?method=DELETE&access_token='.$token
Facebook does not permit applications to delete photos at all.