Google Buzz API - 无法解决错误:“必需参数缺失 - grant_type”

发布于 2024-11-10 14:10:03 字数 1811 浏览 0 评论 0原文

我正在尝试用 python 制作一个桌面应用程序来向 Google Buzz 发布消息。我无法使用 access_token 交换代码(我要求用户在授权应用程序后从浏览器复制粘贴的代码)。

我正在通过以下方式向 www.google.com4/accounts/o8/oauth2/token 进行 POST:

send: 'POST /accounts/o8/oauth2/token HTTP/1.1\r\nHost: www.google.com\r\nAccept-Encoding: identity\r\nContent-Length: 194\r\n\r\nclient_id=XXXXXXX.apps.googleusercontent.com&client_secret=XXXXXXXXXXXXXX&code=4/JFxWkTynH63BruP_dLqtJTV0O_oc&grant_type=authorization_code&redirect_uri=urn:ietf:wg:oauth:2.0:oob'
reply: 'HTTP/1.1 400 Required parameter is missing: grant_type\r\n'
header: Cache-Control: no-cache, no-store, max-age=0, must-revalidate
header: Pragma: no-cache
header: Expires: Fri, 01 Jan 1990 00:00:00 GMT
header: Date: Mon, 30 May 2011 09:04:36 GMT
header: Content-Type: text/html; charset=UTF-8
header: X-Content-Type-Options: nosniff
header: X-Frame-Options: SAMEORIGIN
header: X-XSS-Protection: 1; mode=block
header: Server: GSE
header: Transfer-Encoding: chunked
400 Required parameter is missing: grant_type
<HTML>
<HEAD>
<TITLE>Required parameter is missing: grant_type</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Required parameter is missing: grant_type</H1>
<H2>Error 400</H2>
</BODY>
</HTML>

更具体地说,我以这种方式发送参数(复制、粘贴、从上面格式化):

POST /accounts/o8/oauth2/token HTTP/1.1\r\n
Host: www.google.com\r\n
Accept-Encoding: identity\r\n
Content-Length: 194\r\n
\r\n
client_id=XXXXXXX.apps.googleusercontent.com&
client_secret=XXXXXXXXXXXXXX&
code=4/JFxWkTynH63BruP_dLqtJTV0O_oc&
grant_type=authorization_code&
redirect_uri=urn:ietf:wg:oauth:2.0:oob

任何想法/建议/指点?我应该如何修复这个错误?我有什么地方说错了吗?

感谢您的时间和耐心。

最好的问候,

Srivatsan Iyer

I am trying to make a desktop application in python to post messages to Google Buzz. I am not able to exchange the code (the one I am asking the user to copy-paste from the browser after he authorizes the application) with the access_token.

I am doing a POST to www.google.com4/accounts/o8/oauth2/token in the following way:

send: 'POST /accounts/o8/oauth2/token HTTP/1.1\r\nHost: www.google.com\r\nAccept-Encoding: identity\r\nContent-Length: 194\r\n\r\nclient_id=XXXXXXX.apps.googleusercontent.com&client_secret=XXXXXXXXXXXXXX&code=4/JFxWkTynH63BruP_dLqtJTV0O_oc&grant_type=authorization_code&redirect_uri=urn:ietf:wg:oauth:2.0:oob'
reply: 'HTTP/1.1 400 Required parameter is missing: grant_type\r\n'
header: Cache-Control: no-cache, no-store, max-age=0, must-revalidate
header: Pragma: no-cache
header: Expires: Fri, 01 Jan 1990 00:00:00 GMT
header: Date: Mon, 30 May 2011 09:04:36 GMT
header: Content-Type: text/html; charset=UTF-8
header: X-Content-Type-Options: nosniff
header: X-Frame-Options: SAMEORIGIN
header: X-XSS-Protection: 1; mode=block
header: Server: GSE
header: Transfer-Encoding: chunked
400 Required parameter is missing: grant_type
<HTML>
<HEAD>
<TITLE>Required parameter is missing: grant_type</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Required parameter is missing: grant_type</H1>
<H2>Error 400</H2>
</BODY>
</HTML>

More specifically, the I am sending the parameters this way (copy, paste, formatted from above):

POST /accounts/o8/oauth2/token HTTP/1.1\r\n
Host: www.google.com\r\n
Accept-Encoding: identity\r\n
Content-Length: 194\r\n
\r\n
client_id=XXXXXXX.apps.googleusercontent.com&
client_secret=XXXXXXXXXXXXXX&
code=4/JFxWkTynH63BruP_dLqtJTV0O_oc&
grant_type=authorization_code&
redirect_uri=urn:ietf:wg:oauth:2.0:oob

Any ideas/suggestions/pointers? How should I fix this error? Am I wrong anywhere?

Thanks for your time and patience.

Best regards,

Srivatsan Iyer

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟雨扶苏 2024-11-17 14:10:03

[回答我的问题,希望对未来的读者有所帮助]

我设法解决了我的问题。我使用 Python 的 HTTPSConnection 对上述数据进行了 POST。 GAE 可能不太适合它。我改用 google.appengine.api.urlfetch,效果很好! :-)

[Answering my question in the hope that it helps future readers]

I managed to solve my problem. I did a POST of the above data using Python's HTTPSConnection. GAE probably does not go well with it. I used google.appengine.api.urlfetch instead, and it worked just fine! :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文