Facebook Php SDK - getUser()返回始终为0 [英] Facebook Php SDK - getUser() return always 0

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

问题描述

我阅读了这个论坛上的所有主题,但我找不到我的解决方案。



我使用最后一个Php SDK通过Facebook:v3.2.2。 p>

所以我用这个:

  / start fb 
$ facebook = new \Facebook(array(
'appId'=> $ fb_app_id,
'secret'=> $ fb_app_secret,
'cookie' => true,
));

// get id user-fb
$ fbUser = $ facebook-> getUser();

if($ fbUser){
try {
$ fbUserProfile = $ facebook-> api('/ me'); // take user-infos
$ friends = $ facebook-> api('/ me / friends'); //拿他的朋友

} catch(FacebookApiException $ e){
error_log($ e);
$ fbUser = null;
}
}

if($ fbUser){
$ logoutUrl = $ facebook-> getLogoutUrl(array('next'=>('my- url')));
} else {
$ loginUrl = $ facebook-> getLoginUrl(array(
'canvas'=> 1,
'fbconnect'=> 0,
'scope'=>'email,offline_access,publish_actions',
'req_perms'=>'publish_stream,email',
'redirect_uri'=>'my-redirect-url'
));
}

所以我不明白是什么错误
当我测试它,第一次我可以点击loginUrl并获得授权。但是当我再次尝试getUser时,函数 $ facebook-> getUser()再次返回0 ,我再次获得了loginUrl,但是当我点击链接时, m只是重定向回调url ..



我不知道应用程序是否需要Facebook的特殊参数。我的app_id和app_secret是100%确定的。

解决方案

我使用
$ facebook解决了这个问题 - > getLoginUrl(array(
'scope'=>'public_profile',
'redirect_uri'=>'http://www.your_domain/current_page.php'
)) ;


其中'http://www.your_domain/current_page.php'是我正在运行的同一页这个代码

NB使用Facebook php sdk 3.2.3


I read all threads on this forum but I can't find my solution..

I use the last Php SDK by facebook : v3.2.2 .

So I used this:

//start fb
$facebook = new \Facebook(array(  
    'appId'  => $fb_app_id,  
    'secret' => $fb_app_secret,  
    'cookie' => true,  
));

// get id user-fb
$fbUser = $facebook->getUser();

if ($fbUser) {
    try {
      $fbUserProfile = $facebook->api('/me'); // take user-infos
      $friends = $facebook->api('/me/friends'); // take his friend

    } catch (FacebookApiException $e) {
      error_log($e);
      $fbUser = null;
    }
}

if ($fbUser) {
    $logoutUrl = $facebook->getLogoutUrl(array( 'next' => ('my-url') ));
} else {
    $loginUrl = $facebook->getLoginUrl(array(
        'canvas' => 1,
        'fbconnect' => 0,
        'scope' => 'email,offline_access,publish_actions',
        'req_perms' => 'publish_stream,email',
        'redirect_uri' => 'my-redirect-url'
        ));
}

So I don't understand what is wrong.. When I test it, first time I can click on the loginUrl and get authorization . but when I try to getUser again, the function $facebook->getUser() return 0 again and I got the loginUrl again but when I click on the link, I'm just redirect on the callback url..

I'm not sure if the application facebook need special parameters for this. My app_id and app_secret are 100% sure.

解决方案

I solved this issue using
$facebook->getLoginUrl(array( 'scope' => 'public_profile', 'redirect_uri' => 'http://www.your_domain/current_page.php' ));
where 'http://www.your_domain/current_page.php' is the same page where i am running this code
N.B using Facebook php sdk 3.2.3

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

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