开发者

$facebook->getUser() always return zero

Hi I m integrating facebook connect functionality in my website. So I 开发者_StackOverflowused 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. 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..

<?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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜