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

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

问题描述

我正在尝试处理需要来自 Facebook 用户的一些信息的网站,我使用的是 PHP 和 JS SDK.

我在 PHP 中有一个函数:

公共函数 isLoggedOnFacebook() {$user = $this->_facebook->getUser();如果($用户){返回 $this->_facebook->api("/$user");}返回假;}

$this->_facebook 中保存来自 SDK 的 facebook 对象的类.

然后在一个街区我这样做:

isLoggedOnFacebook()): ?><div><fb:login-button show-faces="true" perms="email" width="500"/>

<?php endif ?>

并且 FB JS 环境设置正确(我认为)所以它可以工作.因此,用户会收到弹出窗口并授权该网站.

问题是即使app被用户授权后$user总是0,意思是$facebook->getUser()总是返回0,然后列出用户的人脸,包括登录的用户,但如果我让它调用 $facebook->api('/me') 或其他什么,那么它会抛出无效的令牌异常.

我见过这个问题,但我还没有看到解决方案,我不知道问题出在哪里,我的想法用完了.

在应用程序部分的开发人员 Facebook 页面上有一个网站选项卡,您可以在其中设置站点 URL 和站点域,我认为这是我的问题的原因,但我不知道正是这些字段应该包含的内容.

解决方案

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

这个问题的症状是相似的,当它是由各种不同的事情引起的,所以你可以很好地探索本页提供的不同答案.

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

I have a function in PHP:

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

On a class that is holding the facebook object from the SDK in $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 ?>

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.

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.

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.

解决方案

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屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆