java - google oauth api v2 中缺少 grant_type 参数吗?

标签 java oauth-2.0 token

我正在做这个请求:

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

因此,正如文档所说,我使用这些 header 发出该请求:

"Accept-Encoding": "gzip"
"Content-Type": "application/x-www-form-urlencoded"

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

{"error":"invalid_request","error_description":"Required parameter is missing: grant_type"}

最佳答案

我已经解决了这个问题。问题是我在查询字符串中发送参数,正确的方法是将它们作为 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

希望对你有帮助

关于java - google oauth api v2 中缺少 grant_type 参数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25409069/

相关文章:

python - 无效请求状态 : oauth2 flask

oauth-2.0 - IdentityServer4 JWT 范围作为空格分隔的字符串而不是数组?

android - Android 手机上的 OAuth 安全问题?

perl - 在 Perl 中枚举所有可能长度的有序标记

java - 为什么我不能在 split() 函数中使用 "."作为分隔符?

java - "AWT-EventQueue-1"java.lang.OutOfMemoryError : Java heap space

java - 我想获取选择的所有值,即使它们没有被选择。我应该怎么办?

java - Sobel 运算符不适用于矩形图像

oauth-2.0 - 如何以编程方式为 gcp 创建 oauth 客户端 ID

ios - Apple MusicKit 开发者 token