Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"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 following 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.

like image 670
Alloi Avatar asked Nov 08 '10 05:11

Alloi


People also ask

What is access token in Facebook API?

An access token is an opaque string that identifies a user, app, or Page and can be used by the app to make graph API calls. When someone connects with an app using Facebook Login and approves the request for permissions, the app obtains an access token that provides temporary, secure access to Facebook APIs.

What is an Oauth exception on Facebook?

OAuthException: If you receive an OAuthException error, it means that Edgar doesn't have the correct permissions to access your Facebook accounts right now. The password may have been changed on Facebook or Facebook may have reset your security session.

How do I get a short live access token on Facebook?

Go to https://developers.facebook.com/tools/explorer/ and select your app from the first drop down menu, in the left. Click on the button "Get access token", and in the "Select Permissions" window, click in "Extended Permissions" and check manage_pages and publish_stream, and click in "Get Access Token" blue button.


2 Answers

There are 3 things you need.

  1. You need to oAuth with the owner of those photos. (with the 'user_photos' extended permission)

  2. You need the access token (which you get returned in the URL box after the oAuth is done.)

  3. 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

like image 70
jwmann Avatar answered Sep 21 '22 13:09

jwmann


Try This url with valid userid and access token:

https://graph.facebook.com/{userid}/photos?limit=20&access_token={access_token}

like image 39
Sanchit Avatar answered Sep 21 '22 13:09

Sanchit