1

My goal is to validate user purchases on google server as described here > Purchases.products: get

but i need to authorise the request > Authorisation Documentation

According to Google Play Developer API Authorization Doccumentation in order to generate access and refresh 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>

A successful response will contain your tokens in JSON format:

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

"

i successfully generated code, client_id, client_secret, redirect_uri from console.developers.google.com but when i send the POST 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

i get the the following response when i used Postman:

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

with status code = 400

i get the the following response when i used Chrome :

{
    "error": "invalid_request"
}

How can i get the right response?

4

1 回答 1

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

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

在此处输入图像描述

于 2018-05-10T14:45:13.320 回答