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