"An access token is required to request this resource" while accessing an album / photo with Facebook php sdk
I am using the php sdk to access a user's albums and photos in a website. I am able to login and also able to retrieve all the info about the albums and photos.
However, I am not able to display these photos on the webpage.
When I try the graph API, to get the photo / album like below:
https://graph.facebook.com/131833353530147/picture
I get the fo开发者_JAVA百科llowing error message:
{
"error": {
"type": "OAuthException",
"message": "An access token is required to request this resource."
}
}
But the same is working in while I try to display my profile pic and I do have a valid access token.
Help on this would be greatly appreciated.
There are 3 things you need.
You need to oAuth with the owner of those photos. (with the 'user_photos' extended permission)
You need the access token (which you get returned in the URL box after the oAuth is done.)
When those are complete you can then access the photos like so
https://graph.facebook.com/me?access_token=ACCESS_TOKEN
You can find all of the information in more detail here: http://developers.facebook.com/docs/authentication
Try This url with valid userid and access token:
https://graph.facebook.com/{userid}/photos?limit=20&access_token={access_token}
Login to your Facebook.
Go to http://graph.facebook.com
You will find all your feeds with their corresponding access codes. e.g https://graph.facebook.com/me/home?access_token=2227470867|2.AQAQ6FqN8IW-PUrR.3600.1309471200.0-137977022924629|0sbmdhJN6o9y9J4GDWs8xEygyX8
Enjoy!
To get an access token: facebook Graph API Explorer
You can customize specific access permissions, basic permissions are included by default.
To get the actual access_token
, you can also do pro grammatically via the following PHP code:
require 'facebook.php';
$facebook = new Facebook(array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
));
// Get User ID
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
$access_token = $facebook->getAccessToken();
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
Well, you are having a valid access token to access your information and not others( this is because you got logged in and you have given permission to access your information). But the picture owner has not done the same (logged in + permission ) and so you are getting a violation error.
To obtain permission see this link and decide what kind of informations you want from any user and decide the permissions. Later on embed this in your code. (In the login function call)
Thanks
精彩评论