$ facebook-> getUser()返回零 [英] $facebook->getUser() returns zero

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

问题描述

我对Facebook PHP API有问题。这是我的代码:

 <?php 
$ facebook = new Facebook(array(
' appId'=>'MY_APP_ID',
'secret'=>'MY_SECRET'
));

$ uid = $ facebook-> getUser();
if($ uid){
try {
$ user = $ facebook-> api('/ me');
} catch(Exception $ e){
error_log($ e);
$ user = null;
}
}

如果(!$ uid){
$ login_url = $ facebook-> getLoginUrl(array(
'next'=> ;'http://www/mywebsite.com',
'redirect_uri'=>'http://www/mywebsite.com',
'scope'=>'email,publish_stream, user_birthday,user_location'
));

echo'< a href ='。$ login_url。'> TEST TO CONNECT< / a>';
} else {
print_r($ user);
}

我继续拥有TEST TO CONNECT的线条,看起来像$ facebook->的getUser();总是返回0.任何想法?



感谢您的帮助

解决方案

你能看到任何错误吗?你被带到登录页面并返回?或者是这样吗?



您的代码中的错误似乎属于 if(!$ uid)然后生成登录URL。



我没有找到什么'next'=> 'http://www/mywebsite.com',在那里。



尝试使用这个:

  $ loginUrl = $ facebook-> getLoginUrl(
array(
'scope'=>'publish_stream,read_friendlists,user_photos',
'redirect_uri'=> $ redirecturi

);

此外,不要忘记包括Facebook PHP SDK文件。



require_once(facebook.php); //如果文件放在其他位置,则为完整位置。


I've a problem with the Facebook PHP API. here is my code:

<?php
$facebook = new Facebook(array(
    'appId'  => 'MY_APP_ID',
    'secret' => 'MY_SECRET'
));

$uid = $facebook->getUser();
if ($uid) {
    try{
        $user = $facebook->api('/me');
    } catch (Exception $e){
        error_log($e);
        $user = null;
    }
}

if (!$uid) {
    $login_url = $facebook->getLoginUrl(array(  
        'next' =>   'http://www/mywebsite.com', 
        'redirect_uri' =>   'http://www/mywebsite.com', 
        'scope' => 'email,publish_stream,user_birthday,user_location'
    ));

    echo '<a href="'.$login_url.'">TEST TO CONNECT</a>';
} else {
    print_r($user);
}

I keep having the line TEST TO CONNECT so it looks like $facebook->getUser(); always returns 0. Any idea?

Thank you for your help

解决方案

Can you see any errors? Are you being taken to the login page and returned back? Or is it all fine?

The error in your code seems to be under the part if (!$uid) where you then generate the login url.

I dont really find what 'next' => 'http://www/mywebsite.com', does there.

Try using this :

$loginUrl = $facebook->getLoginUrl(
                array(
                   'scope'         => 'publish_stream,read_friendlists,user_photos',
                   'redirect_uri'  => $redirecturi
                )
            );

And also, dont forget to include the Facebook PHP SDK File.

require_once("facebook.php");//or full location if the file is placed elsewhere.

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

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