OAuth.io服务器端不会刷新Google令牌 [英] OAuth.io server-side doesn't refresh Google token
问题描述
首先,请不要将其标记为重复的,因为这与服务器端(PHP)相关,而不是与其他帖子相关的客户端。
m试图通过Oauth.io刷新Google API的令牌。我遵循这和其他许多帖子,但没有运气。不幸的是Oauth.io文档不是最好的。我没有与Twitter和Facebook只有谷歌这个问题。
当我第一次连接时,我得到了refresh_token。然后我需要每天进行一次API调用。
{
access_token:xxx,
token_type:Bearer,
expires_in:3600,
refresh_token:xxx,
id_token:xxx,
provider :google_analytics
}
问题是如何通过Oauth刷新Google令牌。 io?
文件说:
$ b
//如果需要,auth方法自动刷新标记
$ request_object = $ oauth-> auth('facebook',array(
'credentials'=> $ credentials
));
和点此处,但它不能解决问题。所有它做的是,我得到了refresh_token值作为回应。
更新
<根据这个帖子,我尝试过要做:
$ request_object-> post('https://oauth.io/auth/access_token',array(
'code'=>'xxx',//这里我尝试了access_token,refresh_token
'key'=>'xxx',
'secret'=>'xxx',
));
但我得到的是
array(4){
'status'=>
string(5)error
'code'=>
int(401)
'message'=>
string(70)无记名标记无效,请按照oauth2-token链接获取有效的标记!
'data'=>
array(1){
'code'=>
string(17)UnauthorizedError
}
}
仍然没有。
最后我找到了它。您可以使用以下命令刷新access_token:
$ this-> oauth = new OAuth();
$ this-> oauth->初始化($ publicKey,$ secretKey);
- $ refreshedCredentials = $ this-> oauth-> refreshCredentials($ oldCredentials ,true);
或
-
$ request_object = $ oauth-> auth('google_analytics',array(
'credentials'=> $ credentials,
'force_refresh'=> true
));
这两个答案都可以找到这里。我一整天都没有看到它。
我更喜欢使用1st解决方案,因为我想保存新的access_token,以便稍后重用它。你需要记住,你需要传递第一个access_token的refresh_token和最后一个access_token以刷新access_token - refresh_token在用户撤销访问之前不会改变。
At first please do not mark this as duplicated as this is related to server-side (PHP) and not to client-side as other posts.
I'm trying to refresh the token for Google API through Oauth.io. I followed this and many other posts but no luck. Unfortunately Oauth.io documentation is not the best one. I don't have this problem with Twitter and Facebook only Google.
I'm getting refresh_token when I connect for the first time. Then I need to do API call once a day.
{
"access_token":"xxx",
"token_type":"Bearer",
"expires_in":3600,
"refresh_token":"xxx",
"id_token":"xxx",
"provider":"google_analytics"
}
The question is how to refresh Google token through Oauth.io?
The documentation says:
// The auth method automatically refreshes the tokens if needed $request_object = $oauth->auth('facebook', array( 'credentials' => $credentials ));
and points here, but it doesn't solve the problem. All it does is that I'm getting refresh_token value in response.
UPDATE
According to this post I tried to do:
$request_object->post('https://oauth.io/auth/access_token', array(
'code' => 'xxx', // here I tried access_token, refresh_token
'key' => 'xxx',
'secret' => 'xxx',
));
but all I'm getting is
array(4) {
'status' =>
string(5) "error"
'code' =>
int(401)
'message' =>
string(70) "Bearer token invalid. Follow the oauth2-token link to get a valid one!"
'data' =>
array(1) {
'code' =>
string(17) "UnauthorizedError"
}
}
Still nothing.
Finally I found it. You can refresh the access_token using:
$this->oauth = new OAuth();
$this->oauth->initialize($publicKey, $secretKey);
- $refreshedCredentials = $this->oauth->refreshCredentials($oldCredentials, true);
or
$request_object = $oauth->auth('google_analytics', array( 'credentials' => $credentials, 'force_refresh' => true ));
Both answers can be found here. I had it in front of all day long and did not see it.
I prefer using 1st solution as I want to save new access_token so I can reuse it later. And you need to remember that you need to pass refresh_token, which you got with first access_token, along with last access_token to get refreshed access_token - refresh_token doesn't change until user revoke access.
这篇关于OAuth.io服务器端不会刷新Google令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!