为什么Facebook PHP SDK getUser总是返回0? [英] Why is Facebook PHP SDK getUser always returning 0?

查看:149
本文介绍了为什么Facebook PHP SDK getUser总是返回0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用需要Facebook用户的一些信息的网站,我正在使用PHP和JS SDK。

I'm trying to work with a website that requires some information from a Facebook user, I'm using PHP and JS SDKs.

我有一个功能PHP:

public function isLoggedOnFacebook() {
    $user = $this->_facebook->getUser();
    if ($user) {
        return $this->_facebook->api("/$user");
    }
    return false;
}

在<$ c中的SDK中保存Facebook对象的类$ c> $ this-> _facebook 。

然后在一个块上我这样做:

Then on a block I do this:

<?php if (!$this->isLoggedOnFacebook()): ?>
<div>
   <fb:login-button show-faces="true" perms="email" width="500" />
</div>
<?php endif ?>

FB JS环境正确设置(我认为),所以它的工作原理。所以用户得到弹出并授权该网站。

And the FB JS environment is properly set up (I think) so it works. So the user gets the pop up and authorizes the site.

问题是甚至在应用程序被用户授权之后,$ user始终为0,意思是 $ facebook-> getUser()总是返回0,然后列出用户的面孔,包括记录的用户,但如果我调用 $ facebook- &api('/ me')或其他任何东西,那么它会抛出无效的令牌异常。

The problem is even after the app is been authorized by the user $user is always 0, meaning $facebook->getUser() always returns 0, and then lists the faces of users, including the logged user, but if I make it call $facebook->api('/me') or whatever, then it'll throw the invalid token exception.

我看到这个问题,但我没有看到一个解决方案,我不知道
哪里的问题是,我用尽了想法。

I've seen this problem, but I haven't seen a solution, I have no idea where the problem is and I run out of ideas.

有一个网站标签开发人员的Facebook页面在应用程序部分,您可以在其中设置您的站点URL和您的站点域,我认为这是我的问题的原因,但我不知道这些字段应该包含什么。

There's a Website tab on the developers' Facebook page in the apps section, where you can set up your Site URL and your Site Domain, and I'm thinking this are the cause of my problem, but I have no knowledge of exactly what these fields are supposed to contain.

推荐答案

我的具体问题的答案是JS SDK和PHP S的版本之间存在不兼容性DK我正在使用,只是升级他们解决了它。

The answer to my specific issue was that there were incompatibilities between the versions of the JS SDK and PHP SDK I was using and just upgrading them solved it.

这个问题的症状是类似的,当它是由各种不同的事情造成的,所以你可以做得很好在侦察通过本页面提供的不同答案。

The symptom of this issue is similar when it's caused by a variety of different things so you may do very well in scouting through the different answers available in this page.

这篇关于为什么Facebook PHP SDK getUser总是返回0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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