2012-02-09 96 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

改變這一點,你的代碼應該工作。

相關問題