簡體   English   中英

$ facebook-> getUser()始終返回零

[英]$facebook->getUser() always return zero

嗨,我將Facebook Connect功能集成到我的網站中。 所以我用了facebook new graph api。 我用下面的代碼..

.............
.............
    $facebook = new Facebook(array(
  'appId'  => $fbconfig['appid'],
  'secret' => $fbconfig['secret'],
));

$uid = $facebook->getUser();
var_dump($uid);
if($uid)
{
   //do someting
 }
 else
......

但是問題在於$ uid總是為零。 為什么會這樣。 請幫忙..

嘗試這個

$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;   
}

這是您可以使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM