简体   繁体   English

Facebook扩展访问令牌不起作用-但一切似乎都很好(?)

[英]Facebook extended access token doesn't work - but everything seems to be fine (?)

I try to get 60 days facebook access token from server side request. 我尝试从服务器端请求获取60天的Facebook访问令牌。 After user is loged in I check access token through getAccessToken() function from Facebook SDK and after that I use getExtendedAccessToken() which I found somewhere here: How to extend access token validity since offline_access deprecation to ask for 60 days access token: 用户登录后,我通过Facebook SDK中的getAccessToken()函数检查访问令牌,然后使用getExtendedAccessToken()(在以下位置找到我): 自offline_access弃用以来如何扩展访问令牌的有效性 ,要求60天的访问令牌:

   public function getExtendedAccessToken() {

        try {
        // need to circumvent json_decode by calling _oauthRequest
        // directly, since response isn't JSON format.
        $access_token_response =
            $this->_oauthRequest(
                $this->getUrl('graph', '/oauth/access_token'),
                    $params = array(    'client_id' => $this->getAppId(),
                                'client_secret' => $this->getApiSecret(),
                                'grant_type'=>'fb_exchange_token',
                                'fb_exchange_token'=>$this->getAccessToken(),
                 ));

        } catch (FacebookApiException $e) {
        // most likely that user very recently revoked authorization.
        // In any event, we don't have an access token, so say so.
              return false;
        }

        if (empty($access_token_response)) {
             return false;
        }

        $response_params = array();
        parse_str($access_token_response, $response_params);
        if (!isset($response_params['access_token'])) {
            return false;
        }

        return $response_params['access_token'];
        }

Unfortunanely it still won't work my access token expired after 2 hours so I tried also this: 不幸的是,它仍然无法正常工作。我的访问令牌在2小时后过期,因此我也尝试了以下操作:

    public function getSimpleExtendedAccessToken(){

    $request = 'https://graph.facebook.com/oauth/access_token?
                client_id='. $this->getAppId(). 
                '&client_secret=' .$this->getApiSecret(). 
                '&grant_type=fb_exchange_token
                &fb_exchange_token=' .$this->getAccessToken();

    $response = file_get_contents($request);
    $params = null;
    parse_str($response, $params);
    return $params['access_token'];
}

and this one also expired after 2 hours. 并且这两个小时也过期了。 But when I checked what was inside the array $params in the second function there was written: 但是,当我在第二个函数中检查数组$params中的内容时,写了:

Array ( [access_token] => AAAFM5sO7[...] [expires] => 4897 ) 数组([access_token] => AAAFM5sO7 [...] [expires] => 4897)

(That part: " AAAFM5sO7[...] " is of course my access token number) (那部分:“ AAAFM5sO7[...] ”当然是我的访问令AAAFM5sO7[...]

All access tokens which I received are the same: first one from getAccessToken() , second one from getExtendedAccessToken() and third one from getSimpleExtendedAccessToken() . 我收到的所有访问令牌都是相同的:第一个来自getAccessToken() ,第二个来自getExtendedAccessToken() ,第三个来自getSimpleExtendedAccessToken()

Of course when I ask addtionaly more and more for extended access token the expiration number doesn't renew but it's counting down, and that is correct from the point of view of the Facebook documentation, because you can't ask for new access token each minute, but why I can't get 60 days access token? 当然,当我越来越多地要求扩展访问令牌时,到期号不会更新,而是递减,从Facebook文档的角度来看,这是正确的,因为您不能每次都请求新的访问令牌分钟,但是为什么我不能获得60天的访问令牌?

Can anyone help me because I'm a bit cofused? 有人会因为我有点困惑而帮助我吗?

I have a partial answer for my own question. 我对自己的问题有部分答案。 I tryed to received extended access token of my own (and I'm the owner of the app) so Facebook doesn't gave me extended token, but when I tryed with some other I receive regular 60 days access token. 我尝试接收自己的扩展访问令牌(并且我是该应用程序的所有者),因此Facebook没有给我扩展令牌,但是当我尝试使用其他令牌时,我会收到60天的常规访问令牌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM