$fb = new \Facebook\Facebook([
'app_id' => config('config.fb_app_id'),
'app_secret' => config('config.fb_app_secret'),
'default_graph_version' => 'v3.0',
]);
// User info
$fb->setDefaultAccessToken($access_token);
$request = $fb->request('GET', '/me?fields=id,name');
$response = $fb->getClient()->sendRequest($request)->getDecodedBody();
The above code doesn't work and it says "Unsupported get request. Object with ID 'me' does not exist".
Really strange!! This was working fine few days back and suddenly it started throwing Errors. Whats wrong with this code?
Had the same problem.
Didn't notice facebook app was in developer mode.
Was working for me because I was configured as an admin in the app.
You need to add testers for the app
We had the same problem using the python SDK since yesterday on all accounts using permanent tokens.
We solved it now by creating new tokens in the facebook business manager. Maybe this readme also provides some guidance https://github.com/mara/facebook-ads-performance-downloader
There can be multiple reasons for it, you should visit your App's Alerts page first to check if there is some issue with your account:
https://developers.facebook.com/apps/<APP_ID>/alerts/inbox/?business_id=<BUSINESS_ID>
You cannot access live data if your application is in development mode.
The Alerts look like this:
Related
I am trying to use Explicit Sharing with built in watch action. Here is my code
$post_action = $facebook->api(
'me/video.watches',
'POST',
array(
'video' => "$post-link",
'fb:explicitly_shared'=>true
)
);
When I set fb:explicitly_shared to false the activity is shown on both recent activity and activity log. But when i set it to true the activity is only shown on activity log, not to the recent activity, not to the users timeline.
I have read all the documentation on Facebook about Explicit Sharing but i cant find out why is this happening.
All the results I mentioned are made with Test Users of this app.
Maybe I have first to submit it on Facebook for approval before I will be able to test it?
After some days of work i found out that Application testers have a bug with explicit share. I tried to post with my developers account and works good!
I'm using the PHP (with js) SDK for authentication around my website.
Until now I've never had a problem with access tokens and everything has run smoothly.
Since the latest updates have been pushed I'm receiving a lot of:
Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in /home/content/54/9505854/html/src/fb/base_facebook.php on line 1106
The access tokens seem to be invalidated (or irretrievable) whenever there is a PHP call to the API. I made a simple page that uses and this has always simply returned the current access token as expected:
//Facebook PHP SDK
require_once 'src/fb/facebook.php';
//Config
$facebook = new Facebook(array(
'appId' => '...id...',
'secret' => '...secret...',
));
$accessToken = $facebook->getAccessToken();
die($accessToken);
This page still works if loaded immediately after javascript authentication but any navigation away from this page (or indeed a refresh) this script will return the appID and secret as a string in the form [appID]|[secret]
Basically any call to the Facebook object makes the next page navigation unauthenticated.
Also I am not currently storing the retrieved access token as a cookie or in mySQL. Should I?
Any insight into the problem or solution would be really helpful! Thanks
It's a Facebook bug. Description can be found here: https://developers.facebook.com/bugs/404450666302585
This has now been fixed. Update to the latest version of the PHP-SDK (v3.2.2).
I am using php-sdk "3.2.0" got same error..
As per new PHD-sdk mention above https://github.com/facebook/facebook-php-sdk/commit/ca9472b3312dab3fdcfbffb4e45eb091f582dcb7
I have added following code-snippet which fetch saved access token from cache instead giving call to new access token using same code.
if ($code && $code == $this->getPersistentData('code')) {
// short-circuit if the code we have is the same as the one presented
return $this->getPersistentData('access_token');
}
Now, it is returning cache access token instead of [appID]|[secret] one.
It work for me.
A few days ago the facebook connection with our website stopped working all of the sudden, nothing was changed to the code???
Facebook made some changes???
http://www.presbium.sk/vstup-pre-uchadzacov/
require 'facebook-php-sdk/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
));
// Get User ID
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
enter code here
You can find everything you need there:
http://developers.facebook.com/docs/
For login:
http://developers.facebook.com/docs/authentication/
for Facebook Connect:
http://developers.facebook.com/docs/reference/api/
Facebook Login is not an official Facebook expression. The official term for this is Facebook Authentication. Facebook Connect was the expression used for the server to server technology, back when the Rest API was up to date. Now, you have to use the Graph API to do the same things. You can find the infos about the old Rest API here:
http://developers.facebook.com/docs/reference/rest/
But consider these APIs are deprecated and using them for a new development is probably not a good idea.
There are changes to Facebook's API implemented continuously. Some of them may break your app's functionality. A good way to stay-up-to-date about what changes are happening is to following the Operation Developer Love platform updates. There you can find out about bugs and breaking changes to the API. Go through the latest blog updates to see if there is a change you have missed to implement.
Edit:
You wrote:
I did everything as here github.com/facebook/facebook-php-sdk and befor 1 month it works but now it donĀ“t working
The SDK github examples give you a blue print for a general case. The error is most likely something that's app specific, for example which permissions you ask for. I recommend you really go through all the 'breaking changes' in the blog for the past 3 months and see what it can be. For example, the 'offline access' permission was removed a while ago. If your app still asks for it, the apps expected behaviour may break. There are also new requirements for having a privacy policy that if not met may cut off the app's access to parts of the API. I'm not saying these are the source of issue with your app, they're just examples. Real examples.
I am working on a site and i need to post page links from that site to a special user wall or page if something is published on it which means i only need one user to post that question.
the problem which i am facing is access token since i am not trying to show facebook login page in front of website traffic. its not like sharing on user wall we are basically trying to post status on a page automatically so any help for this problem will be appreciated.
i am using the following code which seems to work fine as long as the access token for the page is valid but i need to make something permanent so that i can add all the info in the php code hardcoded and it work for some weeks at-least without changing the api key or token
$appid = 'code';
$appsecret = 'code';
$wall= $pageId = 'code';
$token='page token';
$facebook = new Facebook(array('appId' => $appid, 'secret' => $appsecret, 'cookie' => true));
$params=array( 'message' => $msg,'name' => $title, 'caption' => $title, 'link' =>$uri,'description' => $desc, 'picture' => $pic, 'access_token' => $token,'actions' => json_encode(array('name' => $action_name,'link' => $action_link)) );
$result = $facebook->api($wall.'/feed/','post',$params);
if i make token from the graph api debug page then it works fine but after some time i got the message "OAuthException: An active access token must be used to query information about the current user."
i am really desperate to find something solid for it.
thank you
You can write a backend script (maybe a cron job using the FB PHP-SDK) that runs as the special user and makes the desired FB api calls. For this, you will want to use a long-lived access token, which needs to be renewed every 60 days. You might also try your FB api calls using an App Access Token, which do not expire but also do not support all FB publishing and other operations.
To post to someones wall (or perform any action with the open graph) you must be authenticated with facebook as somebody in their graph or an application that they have granted permission to.
You should look at the permissions that can be set using the oauth scope attribute...
https://developers.facebook.com/docs/reference/dialogs/oauth/
To me it looks like they will need to grant your application publish_stream if you want to write to their friends walls as well as the user that you are authenticated as.
https://developers.facebook.com/docs/reference/login/extended-permissions/
I am trying to determine whether a user is logged into Facebook or not. In the case that I am working with I would like to force him to log into my site even if he is logged into facebook already and has previously given me permissions.
$params = array(
'ok_session' => 'http://localhost/fb_connect?ok_session=1',
'no_user' => 'http://localhost/fb_connect?no_user=1',
'no_session' => 'http://localhost/fb_connect?no_session=1',
);
$next_url = $facebook->getLoginStatusUrl($params);
I was trying to use the code above (per the instructions on http://developers.facebook.com/docs/reference/php/facebook-getLoginStatusUrl/) to determine what flow I need to guide my users through, but in the case when there is 'no_session' aka nobody is logged into Facebook, instead of getting the 'no_session' url specified by the $params, I get the message Application Error on the facebook "check login status page"
Any suggestions are welcome
You're correct, its broken:
http://developers.facebook.com/bugs/295348980494364