0
我試圖將授權碼轉換爲訪問令牌,並且我得到了「BAD REQUEST」 (400)和空的響應主體。Oauth2從UBER獲取access_token
這裏是我的代碼:有關docs
Scanner in = new Scanner(System.in);
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("https://login.uber.com/oauth/token");
post.setRequestHeader("Content-Type", URLEncoder.encode("application/x-www-form-urlencoded", "UTF-8"));
post.setParameter("grant_type",URLEncoder.encode("authorization_code", "UTF-8"));
post.setParameter("client_id",URLEncoder.encode("mq_LxaL0P-Kn8Wq3TmuhztFkOhISxReq", "UTF-8"));
post.setParameter("client_secret",URLEncoder.encode("MY_SECRET", "UTF-8"));
post.setParameter("redirect_uri",URLEncoder.encode("https://jfpmrvbais.localtunnel.me/TaxyNow/webresources/generic", "UTF-8"));
post.setParameter("code", URLEncoder.encode("S9UOTmXLGp20GF6y7TFf9pw5Pkekrl", "UTF-8"));
client.executeMethod(post);
String responseBody = post.getResponseBodyAsString();
String statusCode= post.getStatusText();
UBER。
我正在尋找兩天的解決方案。另外我在stackoverflow中檢查了所有類似的問題,結果我什麼都沒發現。
非常感謝
編輯: 問題解決了,下面是工作代碼:
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("https://login.uber.com/oauth/token");
post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
post.setRequestHeader("Accept", "application/json");
post.setParameter("client_secret",MY_SECRET);
post.setParameter("client_id",clientId);
post.setParameter("grant_type", "authorization_code");
post.setParameter("redirect_uri", REDIRECT_URL);
post.setParameter("code", code);
一件重要的事情: 他們要求你插入您在上插入相同REDIRECT_URL請求。
是的,我試過谷歌庫..最後我解決了它看到編輯問題。 – giladbigel