$ facebook-> getUser()返回零 [英] $facebook->getUser() returns zero
问题描述
<?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-> getUser()返回零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!