$ facebook->的getUser()总是返回0 [英] $facebook->getUser() always returns 0

查看:112
本文介绍了$ facebook->的getUser()总是返回0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/6790272/why-is-facebook-php-sdk-getuser-always-returning-0\">Why实是PHP SDK的getUser总是返回0?


我用下面的code认证Facebook的使用和调整他们,如果没有登录或需要获得许可到登录页面。问题的getUser()始终返回0引起code卡住在重定向循环。任何想法?

  include_once(facebook.php);$ APP_ID ='XXXXXXXXXXXX';
$ app_secret ='xxxxxxxxxxxxxxxxxxxxxxxxxxxxx';//初始化的Facebook
$ Facebook的=新的Facebook(阵列(
APPID=&GT; $ APP_ID,
'秘密'=&GT; $ app_secret,
));$ USER = $ facebook-&GT;的getUser();
回声$用户;
如果($用户){
 尝试{
    $ fbme = $ facebook-&GT; API('/我');
  }赶上(FacebookApiException $ E){
    error_log中($ E);
    $ USER = NULL;
  }
}
其他
{
$ loginUrl = $ facebook-&GT; getLoginUrl(阵列('范围'=&GT;'邮件'));
头('位置:'。$ loginUrl);
}


解决方案

在搜索,我发现,我只是使用Facebook API时未添加code'的键值天。系统需要它以验证

当您使用API​​函数$ facebook-> getLoginUrl();它需要你到(当你正确验证)的登录页面只是返回到自己的网站以code =X导航栏中的参数。所以实例Facebook的对象时,您只需使用一个GET请求来捉拿这条信息。

当您的页面重新加载Facebook的API,确保其主要价值之一是
code'=> $ _GET ['code'],
分类..

真的很生气,我必须想出解决办法自己..这里看getLoginUrl()文档的 http://developers.facebook.com/docs/reference/php/facebook-getLoginUrl/ ,你会发现,无处没有说明它返回什么,只是,它授权的应用程序,这意味着什么是地狱。

另外这里发现PHP API文档的主页上 HTTP://developers.facebook .COM /文档/参考/ PHP / ,它指出的所需参数的最小数量是一个应用程序的秘密和APPID。如果是这样的话,那么为什么排序添加code我的问题?

如果我在胡说,请回复。我想知道我的方式错误。)

Possible Duplicate:
Why is Facebook PHP SDK getUser always returning 0?

Am using the following code to authenticate Facebook uses and redirecting them to login page if not logged in or require permission. Problem is getUser() always returns 0 causing the code to get stuck in a redirecting loop. Any ideas?

include_once("facebook.php");

$app_id = 'xxxxxxxxxxxx';
$app_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

// initialize facebook
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
));

$user = $facebook->getUser();
echo $user;
if ($user) {
 try {
    $fbme = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}
else
{
$loginUrl = $facebook->getLoginUrl(array('scope' => 'email'));
header('Location: '.$loginUrl);
}

解决方案

After days of searching I found that I just wasn't adding a 'code' key value when using the Facebook API. The system needs it in order to validate

When you use the API function $facebook->getLoginUrl(); it takes you to a login-page that (when you authenticate properly) simply returns you to your own website with a code="x" parameter in the navigation bar. So when instantiating the Facebook Object you simply use a get request to nab this piece of information.

when your page reloads the Facebook API, make sure that one of its key values is 'code' => $_GET['code'], sorted..

Really angry that I had to figure this out myself.. Look at the getLoginUrl() docs here http://developers.facebook.com/docs/reference/php/facebook-getLoginUrl/ and you'll find that nowhere does it specify what it returns, just that it "authorises" the app, whatever the hell that means.

Also on the main page of the PHP API docs found here http://developers.facebook.com/docs/reference/php/, it states that the minimum number of parameters required are an app secret and an appID. If this is the case, then why does adding the code sort my problem?

If I'm talking nonsense, please respond. I like to know the error of my ways :).

这篇关于$ facebook-&GT;的getUser()总是返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆