以前调过相关,贴下
- 获取code
- 获取token
```php
方法1
accounts.google.com/o/oauth2/v2/au...
方法2
accounts.google.com/o/oauth2/v2/au...
access_type=offline
response_type=code
redirect_uri={your_redirect_uri}
client_id={your_client_id}
scope=www.googleapis.com/auth/androidpub...
跳转至如下地址
your_redirect_uri?code=4/0AWtgzh4lsFpIOSc61vKAvfwOtXIjp7WV5dAb9haMIqSeyXf_40HfGqvpBNxdcsHVcUoaFA&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fandroidpublisher
得到code
4/0AWtgzh4lsFpIOSc61vKAvfwOtXIjp7WV5dAb9haMIqSeyXf_40HfGqvpBNxdcsHVcUoaFA
```php
获取token方式1:
POST /token HTTP/1.1
Host: oauth2.googleapis.com
Content-Type: application/x-www-form-urlencoded
code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7&
client_id={your-client-id}&
client_secret={your-client-secret}&
redirect_uri={you_url}&
grant_type=authorization_code
获取token方式2:
POST /token HTTP/1.1
Host: oauth2.googleapis.com
Content-Type: application/x-www-form-urlencoded
client_id={your-client-id}&
client_secret={your-client-secret}&
grant_type=refresh_token&
refresh_token={you_refresh_token}
```shell
一些错误,以及参考文章
问题1
第一次获取refresh_token,过了几天又失效了,报错如下
“error”: “invalid_grant”,
“error_description”: “Token has been expired or revoked.”
问题2
查询google订单信息,报错大概就是权限问题
{
“error”: {
“code”: 401,
“message”: “The current user has insufficient permissions to perform the requested operation.”,
“errors”: [
{
“message”: “The current user has insufficient permissions to perform the requested operation.”,
“domain”: “androidpublisher”,
“reason”: “permissionDenied”
}
]
}
}
问题3
redirect_uri_mismatch
问题4
直接postman请求获取token可以通,放到代码本地调试443,放到服务器可以(国外服务器,国内没测试)
cURL error 7: Failed to connect to accounts.google.com port 443: Timed out (see curl.haxx.se/libcurl/c/libcurl-err...) for accounts.google.com/o/oauth2/token...
问题5
refresh_token过期,app在测试阶段授权获取的refresh_token只有七天有效,转正式后永久有效(这个还没测)
“error”: “invalid_grant”,
“error_description”: “Token has been expired or revoked.”
“error”: “invalid_grant”,
“error_description”: “Bad Request”
“error”: “invalid_grant”,
“error_description”: “Malformed auth code.”
相关错误资料说明
github.com/googleapis/google-api-n...
推荐文章: