1
我知道这个问题已经发布之前。但他们都没有答案。所以我重新发布这个问题。 我正在尝试获取分析数据。但是在认证之后,我得到访问令牌的'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 )
你能说明更多吗?通过授予你的意思是什么?在我的代码中,令牌第一次运行,失败并在刷新令牌函数中显示'invalid_grant'。刷新是否需要? – Yulong