2017-07-15 165 views
7

我正在使用LinkedIn API从那里获取更新并显示在网站上。在使用OAuth时,我将令牌存储在一个文件中,然后再从那里拉动它以防止登录弹出窗口。但是,一旦我的令牌到期,我不清楚它将如何刷新。以下是如何,我从文件读取令牌 -LinkedIn API OAuth刷新令牌

 $config = json_decode(file_get_contents(".service.dat")); 
     if(isset($config->key) && isset($config->secret)) { 
      $this->access_token = new OAuthConsumer($config->key, $config->secret); 
     } 

为了验证我有以下获得请求令牌 -

function getRequestToken() 
{ 
    $consumer = $this->consumer; 
    $request = OAuthRequest::from_consumer_and_token($consumer, NULL, "GET", $this->request_token_path); 
    $request->set_parameter("oauth_callback", $this->oauth_callback); 
    $request->sign_request($this->signature_method, $consumer, NULL); 
    $headers = Array(); 
    $url = $request->to_url(); 
    $response = $this->httpRequest($url, $headers, "GET"); 
    parse_str($response, $response_params); 
    $this->request_token = new OAuthConsumer($response_params['oauth_token'], $response_params['oauth_token_secret'], 1); 
} 

生成令牌后,我generting授权网址:

function generateAuthorizeUrl() 
{ 
    $consumer = $this->consumer; 
    $request_token = $this->request_token; 
    return $this->authorize_path . "?oauth_token=" . $request_token->key; 
} 

LinkedIn文档声明以下关于刷新令牌:

刷新访问令牌非常简单,可以在没有 授权对话框出现的情况下发生。换句话说,这是一个无缝的过程,不会影响您的应用程序的用户 体验。只需让您的应用程序通过授权 流程即可获取一个新的访问令牌,并额外提供60天的使用期限。

我不清楚这意味着什么。如果我必须重新从获取请求令牌一路重做,那么是否需要我再次发出http请求并且不得不弹出登录屏幕?我如何避免它?将欣赏建议。

谢谢。

回答