45

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.

sth
  • 222,467
  • 53
  • 283
  • 367
Alloi
  • 663
  • 2
  • 7
  • 10

6 Answers6

30

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

sth
  • 222,467
  • 53
  • 283
  • 367
jwmann
  • 608
  • 10
  • 19
  • 5
    This was the answer for me, it turns out that the Access Token box at the top of the Graph API Explorer is purely for decoration and bears no relevance to the query you write below. 1/10 would not use a UI like this again – Andrew Bullock Mar 23 '14 at 19:51
  • I face (#210) A page access token is required to request this resource. this error when I want to get a page ratings – Krunal Pandya Aug 20 '18 at 07:28
6

Try This url with valid userid and access token:

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

falsarella
  • 12,217
  • 9
  • 69
  • 115
Sanchit
  • 61
  • 1
  • 1
4
  1. Login to your Facebook.

  2. Go to http://graph.facebook.com

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

Shawinder Sekhon
  • 1,569
  • 12
  • 23
  • 4
    An access token is not permanent. It needs to be initialized properly. This tip is useful for testing, but should not be implemented in an application. – rds Oct 08 '12 at 23:19
3

To get an access token: facebook Graph API Explorer

You can customize specific access permissions, basic permissions are included by default.

Ujjwal Singh
  • 4,908
  • 4
  • 37
  • 54
2

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;
   }
 }
sakibmoon
  • 2,026
  • 3
  • 22
  • 32
Peter Teoh
  • 6,337
  • 4
  • 42
  • 58
  • 1
    What I don't understand is that I'm calling from a website. That is to say, I'm not an app seeking permission to view photos, I'm a website with no YOUR_APP_ID. – Kirk Ross Jun 25 '15 at 03:41
  • where to download facebook.php ? – 151291 Jul 03 '18 at 09:00
  • the above code is in fact generated by some application generator. But you can get lots of such similar sample when you download the Facebook Developer SDK: https://developers.facebook.com/docs/php/gettingstarted – Peter Teoh Jul 05 '18 at 11:59
0

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

Community
  • 1
  • 1
sashtinathan
  • 591
  • 4
  • 6