1) I got my facebook app setup.
2) I got my facebook page id, app_secret and access token.
function fetchUrl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$feedData = curl_exec($ch);
curl_close($ch);
return $feedData;
}
$profile_id = "288644066152";
//App Info, needed for Auth
$app_id = "appid";
$app_secret = "app_secret"; // do not expose app secret!
//Retrieve auth token
$authToken = fetchUrl("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id={$app_id}&client_secret={$app_secret}");
$json_object = fetchUrl("https://graph.facebook.com/{$profile_id}/feed?{$authToken}");
print_r($json_object);
RETURNS:
{"data":[]}
Any help out there?
Thanks
There are 2 types of access tokens. The user access token, & the app access token.
Try something like:
https://www.facebook.com/dialog/oauth?client_id=******&redirect_uri=*************&scope=user_about_me,publish_stream,friends_about_me,****&state=SOMETHING
Related
I have everything set up and everything was working properly. I have a popup where the user can reply to a review on their business page. This was also working fine.
My code looks like this:
$url = "https://graph.facebook.com/v3.2/221454575852164769/comments";
$attachment = array(
"access_token" => $page_access_token,
"message" => "Thank you so much!!",
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($attachment));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$comment = curl_exec($ch);
curl_close ($ch);
$comment = json_decode($comment, TRUE);
This was working fine. Even now this script is working but the issue is it returns this error
Unsupported post request. Object with ID '221454575852164769' does not exist, cannot be loaded due to missing permissions, or does not support this operation
Even after the Curl receives error when I go and check into the reviews on Facebook the comment was successfully posted.
Any help?
From the duplicate I flagged, you'll see you may need to submit your app for App Review to Facebook for permissions.
https://developers.facebook.com/docs/facebook-login/permissions/v3.0
How do I test a Facebook app since the recent introduction of login review?
Either that or you mis-typed a paramater/variable, hence the incorrect 18-digit ID number since it can't reference that instance of an object.
How get list of transactions with all my btc addresses with HD account to json format. PHP. I need in link for it
$json_url = "http://127.0.0.1:3000/merchant/$guid/accounts/0?password=$pass";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $json_url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$content = json_decode(curl_exec($ch));
curl_close ($ch);
How to post a notification to users as application using facebook php sdk?
I have attached an image, in that picture we can see application from SongPop post a notification to me. I want to make something like this. I think this app post notification to their users, can I post a notification to a spesific user?
you have to a canvas page url set to in your app config then try with this code
$url = "https://graph.facebook.com/$user_id/notifications";
$notification_message = 'My Example Notification Message';
$app_access_token = $app_id . '|' . $app_secret;
$attachment = array(
'access_token' => $app_access_token, // access_token is a combination of the AppID & AppSecret combined
'href' => '', // Link within your Facebook App to be displayed when a user click on the notification
'template' => $notification_message, // Message to be displayed within the notification
);
// set the target url
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output
$result = curl_exec($ch);
curl_close ($ch);
I'm using the Graph API code that uses an acces_token and an id_page with permissions to post to a fan page. It works as long as the user is logged, but when I log out the access_token expires and I can't publish to fan page.
How can I make my application to be able to publish at any time, even when the user is not logged in?
This is my code:
<?php
$page_access_token = 'AAAFNxxxx';
$page_id = '15203xxx';
$data['picture'] = "https://www.google.it/logos/2012/moby_dick12-hp.jpg";
$data['link'] = "http://www.google.it/";
$data['message'] = "Test";
$data['description'] = "Lorem ipsum dolor sit amet";
$data['access_token'] = $page_access_token;
//curl connection
$post_url = 'https://graph.facebook.com/'.$page_id.'/feed';
$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); ?>
You can use extended token to post when the user has logged out, by retrieving the same exchanging you own client_id (your app_id), your app_secret, and the non-expired, short-lived access_token
https://graph.facebook.com/oauth/access_token?
client_id=APP_ID&
client_secret=APP_SECRET&
grant_type=fb_exchange_token&
fb_exchange_token=EXISTING_ACCESS_TOKEN
Make pending posts in your word press blog, connect your blog with networkbloggers and fanpage.So it will be: Your awaesome WP + Networkbloggers = post on Facebook Fanpage
That must work i'm using it long time every time my post enter on my facebook fan page no need app. or something more complicate
I am quite confused using the Facebook application in the iframe. I granted permissions to the app and accessed to it, but the application acts very strange. If I try to test myself withe the code:
$app = array(
'appId' => 'yyy',
'secret' => 'xxx',
'cookie' => true
);
$facebook = new Facebook($app);
$user_id = $facebook->getUser();
I get 0. On the other hand, if I use this kind of code:
$canvas_page = 'http://www.bandito.sk/facebook/canvas.php';
$auth_url = "https://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($canvas_page)."&scope=user_about_me,user_birthday,email,user_status";
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
I get all what I need. But I just don't understand, the Facebook doesn't even send a signedRequest() in the first example. Do I have to login even tough I use the application inside Facebook as a canvas page?
OK found it on my own
$request_ids = explode(',', $_REQUEST['request_ids']);
print_r($request_ids);
foreach($request_ids AS $request_id){
$request_uri=$request_id."_".$data[user_id];
$ch = curl_init('https://graph.facebook.com/'.$request_uri.'&access_token='.$data[oauth_token]);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
$response = curl_exec($ch);
var_dump($response)."<br>";
}