2

我有以下代码:

$facebook = new Facebook(array('appId' => $FB_APP_ID,
                             'secret' => $FB_APP_KEY,
                             'cookie' => true));
$fb_sess = $facebook->getUser();

if (empty($fb_sess)) {

  $url = $facebook->getLoginUrl(array('response_type'=>'token',
                                        'scope' => 'email'));
  header("Location: $url");

}

$me = $facebook->api('/me');
...

问题是 $fb_sess 始终为 0,因此 empty($fb_sess) 始终为 true,因此重定向到登录 URL 会不断重复。我的应用程序似乎配置正确,并且我使用的是最新的 PHP SDK。有什么线索可以解决这个问题,或者至少知道发生了什么?

4

2 回答 2

0

I realize this question is old, but I will answer it in case someone comes here from google (as I did).

First of all, comment out this line:

header("Location: $url");

and replace it with something like this:

echo "the user appears to be empty try to <a href=".$url.">login</a>";

This way you have the opportunity to see if there's a problem and the user won't get lost in an endless redirection loop. Most likely the error message will be appended to the URL, it'll look something like this:

error_code=901&error_message=This+app+is+in+sandbox+mode.++Edit+the+app+configuration+at+http%3A%2F%2Fdevelopers.facebook.com%2Fapps+to+make+the+app+publicly+visible

The problem in this example is the app is in sandbox mode.

于 2013-10-22T19:54:14.610 回答
0

您缺少 redirect_uri 参数。添加redirect_uri

$params = array(
'scope' => 'email',
     'response_type'=>'token',
'redirect_uri' => 'http url after login',
);

所以这将在登录后确认只有用户返回到页面。

于 2012-04-05T11:07:14.250 回答