[英]$facebook->getUser() always return zero
Hi I m integrating facebook connect functionality in my website. 嗨,我将Facebook Connect功能集成到我的网站中。 So I used facebook new graph api. 所以我用了facebook new graph api。 I used following code.. 我用下面的代码..
.............
.............
$facebook = new Facebook(array(
'appId' => $fbconfig['appid'],
'secret' => $fbconfig['secret'],
));
$uid = $facebook->getUser();
var_dump($uid);
if($uid)
{
//do someting
}
else
......
but problem is that $uid always comes zero. 但是问题在于$ uid总是为零。 Why this is happening. 为什么会这样。 Please help.. 请帮忙..
Try This 尝试这个
$user = null;
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
));
$user = $facebook->getUser();
if ($user) {
echo "user";
}
else
{
echo("<script language=\"javascript\">");
echo("top.location.href = \"http://apps.facebook.com/myapp\";");
echo("</script>");
exit;
}
this is code by which you can login with fb account.. 这是您可以使用fb帐户登录的代码。
<?php
$cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET);
if(isset($cookie))
{
$first_name = json_decode(@file_get_contents('https://graph.facebook.com/me?access_token=' .$cookie['access_token']))->first_name;
$last_name = json_decode(@file_get_contents('https://graph.facebook.com/me?access_token=' .$cookie['access_token']))->last_name;
}
?>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({appId: <?php echo FACEBOOK_APP_ID;?>, status: true, cookie: true, xfbml: true});
FB.Event.subscribe('auth.logout', function(response) {});
FB.Event.subscribe('auth.sessionChange', function(response) {
if (response.session) {
FB.api('/me', function(response) {
if(response.id!='undefined')
{
window.location='Fbaccess.php?first_name='+response.first_name+'&last_name='+response.last_name+'&email='+response.email;
}
else
{
window.location='login.php';
}
});
} else {
// The user has logged out, and the cookie has been cleared
}
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.