Invalid OAuth access token for Facebook - php

I'm trying to make a simple get request via the Facebook PHP SDK, this way :
$rep = $fb->get('/me',$appsecret_proof);
and here's my configuration :
$config_bis = array(
'app_id' => $config['params_api'][EnvironnementExecution::if_prod() ? 'prod' : 'dev']['config']['appId'],
'app_secret' => $config['params_api'][EnvironnementExecution::id_prod() ? 'prod' : 'dev']['config']['secret'],
'default_access_token' => $config['params_api'][EnvironnementExecution::if_prod() ? 'prod' : 'dev']['access_token'],
);
I stock the Facebook configuration data in a . yml file. The issue is Facebook SDK return me that the access_token is invalid even if I checked it before via the Facebook developer interface.
[2015-10-22 11:26:35] Facebook\Exceptions\FacebookResponseException (pid : 11136) : Invalid OAuth access token.
So any ideas ? Thanks

Related

New Instagram API PHP

1) Regarding the new Instagram API, is there another way, than curl, but still in PHP to post a photo (like Facebook API)?
// (For example) :
// Possibility to install Instagram SDK with composer ? And then:
use Instagram\Instagram;
$ insta = new Instagram ([
'app_id' => '',
'app_secret' => '',
'default_graph_version' => '',
]);
$ response = $ insta-> post ('/where', $ data, 'token');
// Like Facebook, you see :-)
2) Is it necessary to need ALL these 3 permissions : manage_pages, instagram_basic and Instagram Public Content Access?

Facebook Graph API: retrieve basic profile information without access_token?

Just that, I'm reading the documentation and it's seems like you can get access to the basic information without auth. But i'm getting an error
the code
$fb = new Facebook([
'app_id' => '...',
'app_secret' => '...',
'default_graph_version' => 'v2.2'
]);
$response = $fb->get('/1000785'); // a valid ramdom user_id
and the response
Type: Facebook\Exceptions\FacebookSDKException
Message: You must provide an access token.
File: ...src/Facebook/FacebookRequest.php
So, should I need to implement the "classic" login anyway?
Ok, just to clarify this issue. It's enough just generating an app access token.
How to generate Facebook App Access Token?
Simply, concatenating app_id and app_secret with a pipe symbol.
$appAccessToken = $config['app_id'] . '|' . $config['app_secret'];
$response = $fb->get('/0123456789', $appAccessToken);
Cheers!

Facebook PHP SDK: Unknown path components

I'm trying to validate Facebook App ID and App Secret. With Graph Explorer, I'm able to use access token in shape of {APP_ID}|{APP_SECRET} to get app details on /v2.5/{APP_ID} endpoint.
It doesn't work with PHP SDK though. The error I'm getting is:
Unknown path components: /{APP_ID}
The code I used is this:
$facebook = new Facebook\Facebook( [
'app_id' => $app_id,
'app_secret' => $app_secret,
'default_graph_version' => '2.5',
] );
$facebook->get( '/' . $app_id, $app_id . '|' . $app_secret );
It does the validation, because with invalid app ID I'm getting:
Error validating application. Cannot get application info due to a system error.
And with invalid secret:
Invalid OAuth access token signature.
How can I get the app details just like in graph explorer? I have no idea what I'm doing wrong, the request seems to be correct. Please help.
There is a typo in default_graph_version. It needs to be prefixed with v (standing for version), so the correct declaration is:
'default_graph_version' => 'v2.5',

Share post via facebook php sdk version 4.0.9, Graph API v2.0

Using facebook php sdk version 4.0.9 & Graph API v2.0
Here is my application settings for publishing post.
My code is :
$requestjojo = new FacebookRequest($session, 'POST', '/me/feed', array('message' => 'testing'));
$responsejojo = $requestjojo->execute();
// get response
$graphObjectjojo = $responsejojo->getGraphObject()->asArray();
// print Graph data
echo '<pre>' . print_r( $graphObjectjojo, 1 ) . '</pre>';
This is not working for me, I want to know where's the bug.
Note : I am getting user data(user profile) properly from this sdk.
Using echo 'Login';
for login button, when login with Facebook, Facebook is not asking me for this extended permission(publish_stream) too.
The loginUrl is not build up properly.
$helper->getLoginUrl(array(
'scope' => 'publish_stream',
'redirect_uri' => $your_redirect_uri
));
Finally, got the answer.
The reason is that "publish_stream" is now deprecated; use "publish_actions" instead.
From :
Error (#200) The user hasn't authorized the application to perform this action

Facebook - Retrieving recent posts from FB API in PHP

I am working on a script to pull recent Facebook posts/status updates for a specific using the Facebook API. I downloaded the FB SDK and searched all over the FB developers site, SO, and other places and it seems like the code below should accomplish what I need. However, although I am not getting an error, I am getting a NULL result.
require 'facebook-php-sdk/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'XXXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXX',
));
$fbApiGetPosts = $facebook->api('***My Name***/feed?limit=5');
var_dump($fbApiGetPosts["data"]);
I have tried using my two FB accounts,(my personal acct and a test account that I created just for this project) as well as one for my company and each time the response was NULL. When I misspelled the account name or used a name that did not exist I got an error, which seems to suggest the request is going somewhere.
In the code above, I also tried var_dump-ing $fbApiGetPosts and that result was also null
Can anybody see what the missing piece of the puzzle is?
I've not used the Facebook SDK, but here is how I retrieve Facebook posts:
$appId = 'XXXXXXXXXXXX';
$token = 'XXXXXXXXXXXXXXXXXXXXXXXX';
$posts = json_decode(
file_get_contents('https://graph.facebook.com/' . $appId . '/feed?
access_token=' . $token
)
);
var_dump($posts->data);
Hopefully this helps!
EDIT:
The token is just called an "Access Token". Here are the instructions for obtaining one. You might find the Access Token Tool helpful, but it's more for debugging existing tokens then creating new ones.
Just use the PHP SDK :
download link : https://developers.facebook.com/docs/php/gettingstarted/
Log your app :
$facebook = new Facebook(array('appId' => 'XXXXX','secret' => 'XXXXX'));
$facebook->setAccessToken('stored access token');
then :
$fbApiGetPosts = $facebook->api('/me/feed');
print_r($fbApiGetPosts);
Here is the Graph doc : https://developers.facebook.com/docs/graph-api/reference/
and the /feed ref : https://developers.facebook.com/docs/graph-api/reference/user/feed/

Categories