如何为Google Play Developers API生成刷新和访问令牌

时间:2018-05-10 10:32:41

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

我的目标是在Google服务器上验证用户购买,如此处所述> 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"
}
  

&#34;

我从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"
}

我如何得到正确的回应?

1 个答案:

答案 0 :(得分:1)

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

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

enter image description here

相关问题