【问题标题】:Uber API - requesting ride in sandbox - Receiving Error: Invalid request - validation_failedUber API - 在沙盒中请求乘车 - 接收错误:无效请求 - 验证失败
【发布时间】:2017-02-12 02:20:03
【问题描述】:

我正在开发 Uber API 并尝试在沙盒中请求搭车。我正在关注这里的 API 指南 - Uber API - POST Request

StringEntity param; OR JSON 如下所示:

{
"product_id": "3145c334-25c6-462d-a2f5-70c38a165746",
"start_latitude": 41.2237329,
"start_longitude ": -73.2304860,
"end_latitude": 41.7220050,
"end_longitude": -73.3159659
}

我的 Java 代码 看起来像:

    String url = "https://sandbox-api.uber.com/v1/requests";
    HttpPost httpPostRequest = new HttpPost(url);
    httpPostRequest.setHeader("Authorization", "Bearer " + accessTokenModel.getAccess_token());
    httpPostRequest.setHeader("Content-Type", "application/json");
    httpPostRequest.setEntity(param);
    HttpResponse httpResponse = client.execute(httpPostRequest);

    response.getWriter().println("Status Code: " + httpResponse.getStatusLine().getStatusCode());

    br = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));

    line = line1 = "";
    while ((line = br.readLine()) != null) {
            response.getWriter().println(line);
            line1 = line1 + line;
    }

我收到了,状态码:422 错误说:

{"fields":{"":"Both start_latitude and start_longitude or start_place_id are required."},"message":"Invalid request","code":"validation_failed"}

我的 JSON 看起来类似于建议的 Uber 示例 .. 我还在设置 JSON 标头 - 授权令牌和内容类型 .. 所以不确定我错过了什么 ..

任何人都可以发现 - 我做错了什么?

提前谢谢你

【问题讨论】:

    标签: java apache-httpclient-4.x uber-api


    【解决方案1】:

    start_longitude 字段名称后附加了一个空格字符:

    "start_longitude "
                    ^ remove this space character
    

    【讨论】:

    • 谢谢亚历克斯 - 就是这样。
    猜你喜欢
    • 2016-08-07
    • 2015-05-21
    • 2020-11-17
    • 1970-01-01
    • 2016-05-17
    • 2021-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多