开发者

problem api facebook v3 [duplicate]

This question开发者_开发技巧 already has answers here: Closed 11 years ago.

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);
                }
            }


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜