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

后端 未结 6 872
执念已碎
执念已碎 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;
       }
     }
    

提交回复
热议问题