0

Possible Duplicate:
facebook Uncaught OAuthException: An active access token must be used to query information about the current user.

I have a problem with v3 of php api facebook.

This is the error: OAuthException: An active access token must be used to query information about the current user.

This is the code:

$facebook = new Facebook(array(
              'appId'  => 'xxxxx',
              'secret' => 'xxxxx',
            ));

            $user = $facebook->getUser();
            $accessToken = $facebook->getAccessToken();

            if ($user) {
                try {
                    $events = $facebook->api('/me');
                } catch (FacebookApiException $e) {
                    echo ($e);
                }
            }
Community
  • 1
  • 1
Dany
  • 2,290
  • 8
  • 35
  • 56

1 Answers1

2

You must redirect to a login url, you can get the url with getLoginUrl method of facebook object:

if ($user) {
     // if accepted              
}else{
    $loginUrl = $facebook->getLoginUrl();  // redirect to this url.
}

When you accept the application, you'll get an access token and be able to use the api.

Headshota
  • 21,021
  • 11
  • 61
  • 82