我在PHP中从LI API获取Access令牌,我的代码会这样做,但令牌在一段时间后过期,所以我需要刷新它,我该怎么做。这是我的代码
global $config;
$params = array('grant_type' => 'authorization_code',
'client_id' => $config['linkedin_key'],
'client_secret' => $config['linkedin_secret'],
'code' => $_GET['code'],
'redirect_uri' => $redirectUrl
);
// var_dump($params);
$url = 'https://www.linkedin.com/uas/oauth2/accessToken?' . http_build_query($params);
$context = stream_context_create(
array('http' =>
array('method' => 'POST',
)
)
);
$response = file_get_contents($url, false, $context);
$token = json_decode($response);
return $token->access_token;