Facebook SDK getAccessToken() problems


Facebook SDK getAccessToken() problems

我在使用facebookSDK时遇到了一些问题,特别是在检索访问令牌时。该应用程序已在Facebook上正确设置,并已获得许可。据我所知,代码是正确的,我不确定getAccessToken()出了什么问题。

$facebook->getAccessToken()返回"12345678|abcdefghijklmnop",基本上是由|分隔的应用程序ID和机密ID组成的某种变量

$facebook->getUser()正在返回"0"

<?php
     require_once("facebook.php"); //Up-to-date SDK files from Git
     $app_id = "12345678"; //replaced with fake
     $app_secret = "abcdefghijklmnop"; //replaced with fake
     $facebook = new Facebook(array(
         'appId' => $app_id,
         'secret' => $app_secret,
         'cookie' => true; //I have tried 'false' here as well
     ));
     $token = $facebook->getAccessToken();
?>

提前谢谢!

$facebook->getAccessToken();返回"12345678|abcdefghijklmnop",基本上是由应用程序ID和秘密ID组成的某种变量,由|分隔

来自Facebook SDK:

  public function getAccessToken() {
    if ($this->accessToken !== null) {
      return $this->accessToken;
    }
    $this->setAccessToken($this->getApplicationAccessToken());
    $user_access_token = $this->getUserAccessToken();
    if ($user_access_token) {
      $this->setAccessToken($user_access_token);
    }
    return $this->accessToken;
  }
  protected function getApplicationAccessToken() {
    return $this->appId.'|'.$this->appSecret;
  }

当您有一个用户签名时,您的访问令牌将是APP ID|APP SECRET(即应用程序令牌)或A RANDOM TOKEN HERE(即用户访问令牌):

$facebook->getUser();

getUser()返回0(与false相同,用户未签名)时,您需要为您的应用程序请求登录和授权(如果尚未授权):

if (!$facebook->getUser())
{
    $login_url = $facebook->getLoginUrl(array(
            'scope' => 'publish_stream' // Permissions goes here
        ) 
    );
?>
    <script type="text/javascript">
        top.location.href = " <?php echo $login_url; ?>";
    </script>
<?php
    exit;
}

请参阅此处的可用权限类型:https://developers.facebook.com/docs/authentication/permissions/