0

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

1 Answers1

1

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.

Cormac Driver
  • 2,511
  • 1
  • 12
  • 10
  • Thanks for answering!! As for that, I think that the access token expires after two hours, is there a way to generate it dynamically? – Cristian A. Hurtado Romero Mar 27 '13 at 14:58
  • There's various ways to generate access tokens dynamically, all of which involve going through the OAuth process, either programmatically or visually. One easy way to complete that process is to use the OAuth Wizards provided by Temboo. They'll visually guide you through a 5-step Facebook OAuth process and give you an access token at the end. You can find the Facebook OAuth Wizard on this page (you'll need to sign up for a free account and log in before you see the OAuth Wizard link): https://www.temboo.com/library/Library/Facebook/Reading/PhotoAlbums/ (Full disclosure: I work at Temboo) – Cormac Driver Mar 27 '13 at 16:17