简体   繁体   English

Facebook PHP SDK 3.1.1无限循环

[英]Facebook PHP SDK 3.1.1 infinite loop

i have the following code:我有以下代码:

$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');
...

The problem is that $fb_sess is always 0, so empty($fb_sess) is always true, and so the redirect to the login URL repeats Endlessly.问题是 $fb_sess 始终为 0,因此 empty($fb_sess) 始终为 true,因此重定向到登录名 URL 会无休止地重复。 my app seems to be correctly configured and i'm using the latest PHP SDK. any clue to fix that or at least get an idea of what's happening?我的应用程序似乎配置正确,我使用的是最新的 PHP SDK。有什么线索可以解决这个问题,或者至少了解发生了什么?

You are missing redirect_uri param.您缺少 redirect_uri 参数。 Add redirect_uri添加 redirect_uri

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

So this will confirm after login only the user is returned to the page.所以这将在登录后确认只有用户返回到页面。

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:错误消息很可能会附加到 URL,它看起来像这样:

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.此示例中的问题是应用程序处于沙盒模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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