【发布时间】:2017-12-20 13:03:05
【问题描述】:
我正在使用 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);
}
生成令牌后,我正在生成授权网址:
function generateAuthorizeUrl()
{
$consumer = $this->consumer;
$request_token = $this->request_token;
return $this->authorize_path . "?oauth_token=" . $request_token->key;
}
LinkedIn 文档说明以下有关刷新令牌:
刷新访问令牌非常简单,无需 为用户显示授权对话框。换句话说,它是一个 不会影响您的应用程序用户的无缝流程 经验。只需让您的应用程序通过授权 流以获取一个额外的 60 天的新访问令牌 寿命。
我不清楚这意味着什么。如果我必须从再次获取请求令牌一直重做,那是否不需要我再次发出 http 请求并且必须弹出登录屏幕?我该如何避免呢?将不胜感激。
谢谢。
【问题讨论】:
标签: php oauth linkedin-api