google oauth api v2中缺少grant_type参数?

jsc*_*man 3 java token oauth-2.0

我正在做这个请求:

POST request to
https://accounts.google.com/o/oauth2/token?
client_secret=xxxxx-x8U-tDOJbCPN3&
grant_type=authorization_code&
redirect_uri=[url]
client_id=xxxxxx-e4u1224f7uqjafv7m1lu2ek5ac01isi4.apps.googleusercontent.com&
code=xxxxxxlpdiZfd_LhYu167gK.QvJZYyoaoQAQ3oEBd8DOtNC9kGrnjwI
Run Code Online (Sandbox Code Playgroud)

所以,正如doc所说,我用这些标题发出了这个请求:

"Accept-Encoding": "gzip"
"Content-Type": "application/x-www-form-urlencoded"
Run Code Online (Sandbox Code Playgroud)

但当我这样做时,我得到400:

{"error":"invalid_request","error_description":"Required parameter is missing: grant_type"}
Run Code Online (Sandbox Code Playgroud)

jsc*_*man 10

我已经解决了这个问题.问题是我在查询字符串中发送params,并且正确的方式是将它们发送为x-www-form-urlencoded.所以正确的请求必须是这样的:

POST /o/oauth2/token? HTTP/1.1
Host: accounts.google.com
Cache-Control: no-cache
Postman-Token: b38df5b3-b64f-338a-1374-220647ee05a0
Content-Type: application/x-www-form-urlencoded

client_secret=xxxxx-x8U-tDOJbCPN3%26&grant_type=authorization_code&redirect_uri=myredirecturi&client_id=xxxxxx-e4u1224f7uqjafv7m1lu2ek5ac01isi4.apps.googleusercontent.com&code=xxxxxxlpdiZfd_LhYu167gK.QvJZYyoaoQAQ3oEBd8DOtNC9kGrnjwI
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助