“An access token is required to request this resource” while accessing an album / photo with Facebook php sdk

后端 未结 6 846
执念已碎
执念已碎 2020-12-29 02:08

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.

How

相关标签:
6条回答
  • 2020-12-29 02:19

    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;
       }
     }
    
    0 讨论(0)
  • 2020-12-29 02:23

    Try This url with valid userid and access token:

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

    0 讨论(0)
  • 2020-12-29 02:24

    To get an access token: facebook Graph API Explorer

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

    0 讨论(0)
  • 2020-12-29 02:27

    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

    0 讨论(0)
  • 2020-12-29 02:28

    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

    0 讨论(0)
  • 2020-12-29 02:34
    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!

    0 讨论(0)
提交回复
热议问题