【问题标题】:Uber API: Request Endpoint Yields Error Not SupportedUber API:不支持请求端点产生错误
【发布时间】:2015-11-21 05:38:17
【问题描述】:

我之前在这里看到过另一个类似的帖子,但没有太大帮助。无论如何,我已经完成了所有 OAuth 步骤,并获得了我的访问令牌。以下是我收到的错误 -

{"message":"不支持","code":"not_found"}

我已尝试手动使用 URl 并尝试使用 POST。这是我试过的网址 -

http://sandbox-api.uber.com/v1/requests?access_token=m5MunZjxNVCXbg1p4DXPQjK76DYFaz&product_id=653e6788-871e-4c63-a018-d04423f5b2f7&start_latitude=40.11690903&start_longitude=-75.01428223&end_latitude=40.650729&end_longitude=-74.0095369

收到错误后,我尝试了一个 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


【解决方案1】:

您提供的代码存在一些问题:

  • 沙盒端点使用 HTTPS(而不是 HTTP)
  • 您应该通过 Authorization 标头提供您的访问令牌,而不是 URL 参数。
  • Content-Type 值应为 application/json。

【讨论】:

    猜你喜欢
    • 2017-02-26
    • 2015-08-03
    • 2017-09-29
    • 1970-01-01
    • 2015-06-27
    • 2016-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多