gpt4 book ai didi

android - 如何为 Google Play Developers API 生成刷新和访问 token

转载 作者:行者123 更新时间:2023-11-29 23:56:57 30 4
gpt4 key购买 nike

我的目标是按照此处所述验证用户在谷歌服务器上的购买 > Purchases.products: get

但我需要授权请求> Authorisation Documentation

根据 Google Play Developer API Authorization Doccumentation为了生成访问和刷新 token :

"... sending a POST request to https://accounts.google.com/o/oauth2/token with the following fields set:

grant_type=authorization_code
code=<the code from the previous step>
client_id=<the client ID token created in the APIs Console>
client_secret=<the client secret corresponding to the client ID>
redirect_uri=<the URI registered with the client ID>

成功的响应将包含您的 JSON 格式的 token :

{
"access_token" : "ya29.ZStBkRnGyZ2mUYOLgls7QVBxOg82XhBCFo8UIT5gM",
"token_type" : "Bearer",
"expires_in" : 3600,
"refresh_token" : "1/zaaHNytlC3SEBX7F2cfrHcqJEa3KoAHYeXES6nmho"
}

"

我从 console.developers.google.com 成功生成了代码、client_id、client_secret、redirect_uri,但是当我发送 POST 请求时

https://accounts.google.com/o/oauth2/token?grant_type=authorization_code&code=my_generated_codeA&client_id=generated_client_id&client_secret=generated_client_secret&redirect_uri=my_redirect_uri

我在使用 Postman 时得到以下响应:

{
"error": "invalid_request",
"error_description": "Missing header: Content-Type"
}

状态码 = 400

我在使用 Chrome 时收到以下响应:

{
"error": "invalid_request"
}

如何获得正确的响应?

最佳答案

https://accounts.google.com/o/oauth2/token?grant_type=authorization_code&code=my_generated_codeA&client_id=generated_client_id&client_secret=generated_client_secret&redirect_uri=my_redirect_uri 是 GET 请求,它不是 POST 请求,因为没有请求正文。

此外,当使用 Postman 时响应

{
"error": "invalid_request",
"error_description": "Missing header: Content-Type"
}

表示您选择了错误的标题。您应该在 Postman 的 Body 选项卡中选择 application/x-www-form-urlencoded 选项。然后记下 key 对值。你会得到这样的东西:

enter image description here

关于android - 如何为 Google Play Developers API 生成刷新和访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50270885/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com