Facebook getUser()始终返回0 [PHP SDK 3.1.1] [英] Facebook getUser() always returns 0 [PHP SDK 3.1.1]

查看:58
本文介绍了Facebook getUser()始终返回0 [PHP SDK 3.1.1]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

fb.php:

ini_set('display_errors','On');
error_reporting(E_ALL);
require_once 'facebook/src/facebook.php';

$facebook = new Facebook( array (
    'appId'  => '****',
    'secret' => '****',
    'cookie' => true
  )
);

$user = $facebook->getUser();

if ($user) {
    var_dump($user);
  $logoutUrl = $facebook->getLogoutUrl();

  print '<a href="'.$logoutUrl.'">Logout</a>';
} 
else {
    $loginUrl = $facebook->getLoginUrl();
  print '<a href="'.$loginUrl.'">Login</a>';
}

这是我的简单代码; 单击链接后,接受权限框,然后将我重定向到脚本,并获取以下参数:http://mydomain.com/fb.php?state=82e166c6a85fd3b44ad655851f885b73&code=AQCMo6L5z-K5juFl3cojl80KllKQ8JE2iKMaOFSmHhHgAFd_V-BfD8YZwbiKQasNuHSbcc4St-9B2gggwEMygn223u8BVK9zXKctEui-y20rcmydx-uf65sw5v6o4XN3k9Lnvtg0jg7h1C9XGC3S1sW32X65CI6kjbe7GXHICpMsT833wDxG1voS7enq9uYm1MGrp83ceTmKvoKGyn_iYby0#_=_

This is my simple code; When the link is clicked, and accept the permission box, then I'm redirected to the script, and get this params: http://mydomain.com/fb.php?state=82e166c6a85fd3b44ad655851f885b73&code=AQCMo6L5z-K5juFl3cojl80KllKQ8JE2iKMaOFSmHhHgAFd_V-BfD8YZwbiKQasNuHSbcc4St-9B2gggwEMygn223u8BVK9zXKctEui-y20rcmydx-uf65sw5v6o4XN3k9Lnvtg0jg7h1C9XGC3S1sW32X65CI6kjbe7GXHICpMsT833wDxG1voS7enq9uYm1MGrp83ceTmKvoKGyn_iYby0#_=_

出现这些问题后,我发现了此链接

After these issues, I found this link suddenly, getUser became to return 0.(PHP 3.1.1 SDK), but doesn't works for me.

我正在使用PHP Facebook SDK版本3.1.1.

I'm using the PHP Facebook SDK Version 3.1.1.

¿有人知道这里发生了什么事吗?

¿Somebody know whats happening here?

推荐答案

请再次重新检查您的设置,包括appIdsecret,并确保在应用程序仪表板上已禁用 .

Please recheck your settings again including appId, secret and make sure Sandbox Mode is disabled on your apps dashboard.

更改网站域后,我遇到了同样的问题.尽管我正确地更改了request_uri参数,并使用新域更新了我的应用设置,但错误始终出现.然后我意识到我的Facebook APP的ID和SECRET ID已自动更改,没有任何警告!使用新的ID,整个操作再次开始起作用.

I had the same problem after changing the domain of my site. Altough I properly changed the request_uri parameter and updated my app settings with the new domain, the error kept showing up. Then I realized that the ID and the SECRET ID of my Facebook APP had automatically changed with no warning!! The whole thing started working again using the new ID.

一些专家表示,由于沙箱模式,他们也面临与您相同的问题. 在Facebook Developers Apps页面上,确保Sandbox Mode禁用.

Some experts said they also faced same problem as you because of sandbox mode. From the Facebook Developers Apps page, make sure that the Sandbox Mode is disabled.

另一件事是权限范围,您可以设置以下内容:

Another matter is permission scope you can set as following:

$pram = array(
           'scope' => 'user_birthday,read_stream',
           'redirect_uri' => 'http://domain.com/some_where_else/'
        )
$loginUrl = $this->facebook->getLoginUrl($pram);

也许会对您有帮助. 谢谢.

may be it will help you. thanks.

这篇关于Facebook getUser()始终返回0 [PHP SDK 3.1.1]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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