2013-11-27 58 views
1

我正在使用OAuth 2.0進行授權過程。無法獲取訪問令牌

我已要求授權碼這個網址:

https://www.box.com/api/oauth2/authorize?response_type=code&client_id={MY_CLIENT_ID}

然後我就被重定向到box.net登錄頁面授權。

我輸入了我的Box.net帳戶的憑證。 爲account.Then授權訪問我,我在URL編碼的授權碼,併發送這個請求:

https://www.box.com/api/oauth2/token?grant_type=authorization_code&code={AUTHORIZATION_CODE}&client_id={MY_CLIENT_ID}&client_secret={MY_CLIENT_SECRET_ID}

我得到這樣的響應:

{"error":"invalid_client","error_description":"The client credentials are invalid"} 

我已經檢查了我的客戶端Id和Client Secret Id很多次。那些是正確的。什麼可能是這種錯誤信息的原因?

回答

1

隨着官方文檔狀態:

要獲得的access_token,你需要做一個POST請求https://www.box.com/api/oauth2/token以下參數......「,

雖然所有的參數包括client_idclient_secretgrant_type和代碼都是對的,如果您沒有向網址發送POST請求,您將獲得error: "invalid_client"

Try:

curl https://www.box.com/api/oauth2/token \ 
-d 'grant_type=authorization_code&code={your code}&client_id={your client id}&client_secret={your client secret}' \ 
-X POST