2012-02-09 106 views
2

我可以很容易地获得授权代码,但是在尝试交换访问令牌时不断收到错误。无法使用php形式在谷歌oauth上交换令牌授权代码

<FORM action="https://accounts.google.com/o/oauth2/auth" method="post"> 

<input type = "hidden" name = "code" value = "4%2FXR0s9YvmROnHOpNUuiSlfxHE7xj-">  

<input type = "hidden" name = "redirect_uri" value = "http%3A%2F%2Fwww.m1448analytics.com%2Foauth2%2Frecv.php"> 

<input type = "hidden" name = "client_id" value = "502294831256-84q1ar05j14knsh5h2msvofu68e7rpaj.apps.googleusercontent.com"> 

<input type = "hidden" name = "scope" value = ""> 

<input type = "hidden" name = "client_secret" value = "hiding it"> 

<input type = "hidden" name = "grant_type" value = "authorization_code">  

<INPUT type="submit" value="Send"> 

</FORM> 

谷歌称:错误:INVALID_REQUEST 要求的参数丢失:RESPONSE_TYPE 了解更多 请求细节

+1

我会出去肢体,并说你需要添加'response_type'? – EboMike 2012-02-09 01:07:38

+0

正在查看此问题的人。 C2DM已弃用,请前往实施GCM推送通知http://developer.android.com/guide/google/gcm/index.html – bhuvin 2012-08-02 04:56:42

回答

4

你可能缺少response_type=code

response_type参数决定在谷歌的OAuth 2.0端点返回授权码。如果您正在Web服务器上编写应用程序,则应使用code

https://developers.google.com/accounts/docs/OAuth2WebServer

+0

仅供参考,我必须将其加入到'gsutil config'命令生成的URL我。搜索这个错误消息没有给我任何具体包含gsutil的东西。希望这会被索引,以便其他人可以在未来更快地找到它。 – nstenz 2016-01-19 19:10:36

12

您所请求的网址是:

https://accounts.google.com/o/oauth2/auth

这是获得验证码的网址。现在如果你想获得一个令牌,那么URL应该是:

https://accounts.google.com/o/oauth2/token

改变这一点,你的代码应该工作。

相关问题