我知道这个问题之前已经发布过。但他们都没有答案。所以我重新发布这个问题。我正在尝试获取分析数据。但在验证后,我收到访问令牌的“invalid_grant”错误。现在我有相同的代码工作了大约 3 个月,现在突然之间我遇到了这个问题。我已将刷新令牌保存在数据库中,并使用它来获取访问令牌。请求令牌是否有可能过期?请帮忙!
$oauth2token_url = "https://accounts.google.com/o/oauth2/token";
$clienttoken_post = array(
"client_id" => $client_id,
"client_secret" => $client_secret,
"refresh_token" => $refreshToken,
"grant_type" => 'refresh_token'
);
$authObj = getAccessToken($oauth2token_url, $clienttoken_post);
function getAccessToken($oauth2token_url, $clienttoken_post){
$curl = curl_init($oauth2token_url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clienttoken_post);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$json_response = curl_exec($curl);
curl_close($curl);
$authObj = json_decode($json_response);
return $authObj;
}
令牌响应:****************** is - stdClass Object
(
[error] => invalid_grant
)