【发布时间】:2015-11-21 05:38:17
【问题描述】:
我之前在这里看到过另一个类似的帖子,但没有太大帮助。无论如何,我已经完成了所有 OAuth 步骤,并获得了我的访问令牌。以下是我收到的错误 -
{"message":"不支持","code":"not_found"}
我已尝试手动使用 URl 并尝试使用 POST。这是我试过的网址 -
收到错误后,我尝试了一个 POST(感谢我在此处看到的另一篇帖子)到沙箱请求,导致 301 Moved Permanently Response。
我使用的 POST 代码我也在这里找到,我将在下面发布(我对这一切都很陌生)。
URL url4 = new URL("http://sandbox-api.uber.com/v1/requests");
Map<String,Object> params2 = new LinkedHashMap<>();
params2.put("access_token", AccessToken);
params2.put("product_id", productID);
params2.put("start_latitude", latitude);
params2.put("start_longitude", longitude) ;
params2.put("end_latitude", endLatitude);
params2.put("end_longitude", endLongitude);
StringBuilder postData = new StringBuilder();
for (Map.Entry<String,Object> param : params2.entrySet()) {
if (postData.length() != 0) postData.append('&');
postData.append(URLEncoder.encode(param.getKey(), "UTF-8"));
postData.append('=');
postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8")); }
byte[] postDataBytes = postData.toString().getBytes("UTF-8");
HttpURLConnection conn = (HttpURLConnection)url4.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-formurlencoded");
conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
conn.setDoOutput(true);
conn.getOutputStream().write(postDataBytes);
Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
for ( int c = in.read(); c != -1; c = in.read() )
System.out.print((char)c);
所以我只是在这里做一些根本错误的事情吗?我已经得到了估算/产品,所以我不确定我做错了什么。
为奇怪的格式道歉,这里是新的,它似乎不想让我缩进某些行。
谢谢
【问题讨论】:
-
您在哪个国家/地区需要优步 API 服务?
-
这是针对北美的,所以我认为这个国家不应该成为问题。
标签: url post http-status-code-301 uber-api