Facebook SDK getAccessToken()问题 [英] Facebook SDK getAccessToken() problems

查看:727
本文介绍了Facebook SDK getAccessToken()问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在facebook SDK中遇到麻烦,特别是检索访问令牌。该应用程序在Facebook上正确设置并已获得许可。据我所知,代码是正确的,我不知道getAccessToken()发生了什么。



$ facebook-> getAccessToken() ; 正在返回12345678 | abcdefghijklmnop,基本上是由App ID和Secret ID组成的一些变量,分隔为|



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

 <?php 
require_once(facebook.php); //最新的SDK文件从Git

$ app_id =12345678; //替换为假
$ app_secret =abcdefghijklmnop; //替换为假

$ facebook = new Facebook(array(
'appId'=> $ app_id,
'secret'=> $ app_secret,
'cookie'=> true; //我在这里尝试'false'以及
));

$ token = $ facebook-> getAccessToken();
?>

提前谢谢!

解决方案

从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);
}

返回$ this-> accessToken;
}

protected function getApplicationAccessToken(){
return $ this-> appId。'|'。$ this-> appSecret;
}

您的访问令牌将为 APP ID | APP SECRET 哪个是应用程序令牌,或这里有随身携带,这是用户访问令牌,当您有用户签名:

  $ facebook-> getUser(); 

getUser()返回 0 (与 false 相同,用户未签名),您需要申请登录和授权(如果没有授权($)
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b $ login_url = $ facebook-> getLoginUrl(array(
'scope'=>'publish_stream'//权限在这里

);
?>
< script type =text / javascript>
top.location.href =<?php echo $ login_url;?>;
< / script>
<?php
exit;
}

在这里查看可用的权限类型: https://developers.facebook.com/docs/authentication/permissions/


I have been having some trouble with the facebook SDK, specifically retrieving an access token. The App is set up on Facebook correctly and has been given permission. As far as I can tell, the code is correct and I am not sure what is going wrong with getAccessToken().

$facebook->getAccessToken(); is returning "12345678|abcdefghijklmnop", basically some kind of variable which is made up of the App ID and Secret ID separated by a |

$facebook->getUser(); is returning '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();
?>

Thank you in advance!

解决方案

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

Your access token will be APP ID|APP SECRET which is the application token, or A RANDOM TOKEN HERE, which is the user access token, when you have a user signed:

$facebook->getUser();

When getUser() return 0 (which is same as false, and user not signed) you need to request a login, and authorization (if have not authorized yet) for your application:

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

see available permissions types here: https://developers.facebook.com/docs/authentication/permissions/

这篇关于Facebook SDK getAccessToken()问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆