【问题标题】:How do i generate refresh and access token for Google Play Developers API如何为 Google Play Developers API 生成刷新和访问令牌
【发布时间】:2018-10-20 14:32:01
【问题描述】:

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

但我需要授权请求>Authorisation Documentation

根据Google Play Developer API Authorization Doccumentation以生成访问和刷新令牌:

"... 向 https://accounts.google.com/o/oauth2/token 发送 POST 请求,并设置以下字段:

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 格式的令牌:

{
  "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"
}

我怎样才能得到正确的回应?

【问题讨论】:

  • 如何发送 POST 请求?您是通过浏览器、邮递员、Java 代码还是其他方式进行操作?如果您使用 java 发送它,请提供您的源代码。
  • 我是通过邮递员和浏览器完成的

标签: android google-play in-app-billing google-developers-console play-billing-library


【解决方案1】:

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

另外,当使用 Postman 时,响应

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

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

【讨论】:

    猜你喜欢
    • 2021-05-15
    • 2020-08-11
    • 1970-01-01
    • 2020-04-14
    • 2020-09-06
    • 2016-03-13
    • 2014-07-18
    • 2020-09-13
    • 2019-03-08
    相关资源
    最近更新 更多