简体   繁体   中英

Facebook API - Retrieve my own albums and photos

I'm trying to retrieve my albums and photos from facebook using the Facebook api for php. I've created an app now i have my AppId and my AppSecretId. I don't need any login window because I want to display my own photos, not the ones from any other user, but everytime I try to retrieve them, I receive this message "An active access token must be used to query information about the current user."

I know that if I were going to show the photos from another users, then I should ask for their login and then generate the access token, but this is not the case.

I have tried generating an App token and tried to use this as an access token but it's not working either.

This is the code I'm using:

    require_once("facebook/facebook.php");
        try{
            $facebook = new Facebook(array(
                    'appId' => '<APPID>',
                    'secret' => '<SECRETID>',
                    'cookie' => true
            ));

echo($facebook->getUser());
        if(is_null($facebook->getUser()))
        {
                header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos'))}");
                exit;
        }
        $me = $facebook->api('/me');

        $albums = $facebook->api('/me/albums', array('access_token' => $facebook->getAccessToken()));
        echo($albums);
    }catch(Exception $e){
        echo "THIS IS THE ERROR: " . $e->getMessage();
        die;
    }

I hope you can help me with this. Thank you so much!!

The easiest way to generate a Facebook access token for your personal account is to visit their Graph API Explorer. It will automatically generate an access token that you can copy/paste into your code.

https://developers.facebook.com/tools/explorer

Additionally, you can use the 'Get Access Token' button on that page to request an access token with specific permissions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM