Facebook getUser()返回0

时间:2014-02-01 14:19:32

标签: php facebook facebook-graph-api

每次获得Facebook的许可后我都会获得0分。我错了吗?什么是getAccessToken()?

我有一个工作脚本,但我丢失了,任何人都有工作脚本?

这是我的代码:

<?PHP
include_once "src/facebook.php";


$app_id       = "525085840939034";
$app_secret   = "80b8a0095f0af94c1329c7142f11a68d";
$site_url = 'http://'.$_SERVER['SERVER_NAME'].'/Facebook/index.php';




$facebook = new Facebook(array(
  'appId'     => $app_id,
  'secret'    => $app_secret,
  'cookie' => TRUE
  ));

$user = $facebook->getUser();

if($user){
  // Get logout URL
  $logoutUrl = $facebook->getLogoutUrl();
}else{
  // Get login URL
  $loginUrl = $facebook->getLoginUrl(array(
      'scope'         => 'read_stream, publish_stream, user_birthday, user_location, user_work_history, user_hometown, user_photos',
      'redirect_uri'  => $site_url,
      ));
}


echo $user;

?>
<a href="<?=$loginUrl?>">

1 个答案:

答案 0 :(得分:1)

要获得用户,您需要使用代码中缺少的getUser。它应该是

$facebook = new Facebook(array(
  'appId'     => $app_id,
  'secret'    => $app_secret,
  'cookie' => TRUE
  ));

$user = $facebook->getUser();

if($user){
  // Get logout URL
  $logoutUrl = $facebook->getLogoutUrl();
}else{
  // Get login URL
  $loginUrl = $facebook->getLoginUrl(array(
      'scope'         => 'read_stream, publish_stream, user_birthday, user_location, user_work_history, user_hometown, user_photos',
      'redirect_uri'  => $site_url,
      ));
}

getAccessToken()将为您提供SDK使用的当前访问令牌。