我跟随一位LinkedIn员工关注this blog post:
我能够成功获得一个请求令牌,但是authneticate端点的输出没有给我升级令牌,只是看起来像响应的标题:
Array
(
[http_code] => 200
[content_type] => text/html;charset=UTF-8
[url] => https://www.linkedin.com/uas/oauth/authorize?oauth_token=028f7ec6-1958-4678-b3a8-d16302044a02&state=
[header_size] => 1856
[request_size] => 442
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 1.19871
[namelookup_time] => 5.0E-5
[connect_time] => 0.220965
[pretransfer_time] => 0.670871
[size_upload] => 0
[size_download] => 18615
[speed_download] => 15529
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => 0
[starttransfer_time] => 0.978356
[redirect_time] => 0
[headers_recv] => HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
P3P: CP="CAO DSP COR CUR ADMi DEVi TAIi PSAi PSDi IVAi IVDi CONi OUR DELi SAMi UNRi PUBi OTRi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT POL PRE"
X-LI-UUID: DBhiUXDelKFOoB3ftH7sWQ==
X-Frame-Options: SAMEORIGIN
Content-Type: text/html;charset=UTF-8
Content-Language: en-US
Vary: Accept-Encoding
Date: Mon, 04 Nov 2013 09:51:12 GMT
X-Li-Fabric: PROD-ELA4
Access-Control-Allow-Origin: https://www.linkedin.com
Set-Cookie: _lipt=deleteMe; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/
Set-Cookie: leo_auth_token="GST:Uk7Zzwx4o3DYXFK1qbelLVdblluVSJf1pleK7xxCokGHRJTn_Cp6w-:1383558672:dea96f229228bd275df9209719539c4e39a4d8f9"; Version=1; Max-Age=1799; Expires=Mon, 04-Nov-2013 10:21:11 GMT; Path=/
Set-Cookie: sl="delete me"; Version=1; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/
Set-Cookie: sl="delete me"; Version=1; Domain=.www.linkedin.com; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/
Set-Cookie: s_leo_auth_token="delete me"; Version=1; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/
Set-Cookie: JSESSIONID="ajax:1003784593606883111"; Version=1; Path=/
Set-Cookie: visit="v=1&G"; Version=1; Max-Age=63072000; Expires=Wed, 04-Nov-2015 09:51:12 GMT; Path=/
Set-Cookie: lang="v=2&lang=en-us"; Version=1; Domain=linkedin.com; Path=/
Set-Cookie: bcookie="v=2&02c5bfa3-2725-4dfa-87b7-fb94e53694ff"; domain=.linkedin.com; Path=/; Expires=Wed, 04-Nov-2015 21:28:44 GMT
Set-Cookie: bscookie="v=1&2013110409511298f7fecd-d5cf-4b4a-8858-0b0360a85c34AQHbOIOpgxJguF5jetM44DFwg7CZZPf8"; domain=.www.linkedin.com; Path=/; Secure; Expires=Wed, 04-Nov-2015 21:28:44 GMT; HttpOnly
Pragma: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: no-cache, no-store
Transfer-Encoding: chunked
Connection: keep-alive
X-Li-Pop: PROD-ELA4
Set-Cookie: X-LI-IDC=C1
)
部分代码,如果遗漏任何内容只是问,我会将其添加:
private static $REFRESH_TOKEN_RESOURCE = 'https://api.linkedin.com/uas/oauth/requestToken?scope=r_fullprofile+rw_nus+w_messages+rw_groups+r_emailaddress+r_contactinfo+r_network';
private static $OAUTH_RESOURCE = 'https://www.linkedin.com/uas/oauth/authenticate?oauth_token=';
public static $TOKEN_REFRESH_INTERVAL = 55;//5 days before expiry
public function refreshToken(){
try{
$requestToken = $this->getConnector()->oauthc->getRequestToken(self::$REFRESH_TOKEN_RESOURCE, '');
$tokenData = json_decode($this->api(self::$OAUTH_RESOURCE . $requestToken['oauth_token'], OAUTH_HTTP_METHOD_POST), true);
echo '<pre>';
print_r($tokenData);
echo '</pre>';
}
catch(Exception $e){
throw $e;
}
return $tokenData;
}
//main:
if($mediaConnection instanceof LinkedInConnection && $db->getTimeSinceLastTokenUpdate($userId, $mediaId) >= LinkedInConnection::$TOKEN_REFRESH_INTERVAL){
// exit('here');
try{
$mediaConnection->setTokensToDefault();
$tokenData = $mediaConnection->refreshToken();
$mediaConnection->setAccessToken($tokenData[USER_TOKENS_COLUMN_KEY_OAUTH_TOKEN]);
$mediaConnection->setAccessTokenSecret($tokenData['oauth_token_secret']);
$db->setUserTokens($userId, $mediaId, $mediaConnection->getAccessToken(), $mediaConnection->getAccessTokenSecret());
}
catch(Exception $e){
$mediaConnection->setTokensToDefault();
$returnQueryString = Utils::addQueryParameter($returnQueryString, INPUT_KEY_NAME_SAVE_TOKENS_TO_DB_MARKER, Utils::INPUT_VALUE_DEFAULT);
$returnQueryString = Utils::addQueryParameter($returnQueryString, INPUT_KEY_NAME_TEMPORERALY_SAVE_TOKENS_TO_DB_MARKER, Utils::INPUT_VALUE_DEFAULT);
$mediaConnection->authenticate($returnQueryString);//Redirect use to login, seemless refresh required valid token + logged in user, O.
}
}
请指教, 奥列格。