Uber API - requesting ride in sandbox - Receiving Error: Invalid request - validation_failed
Uber API - requesting ride in sandbox - Receiving Error: Invalid request - validation_failed
我正在使用 Uber API 并尝试在沙盒中叫车。我正在关注这里的 API 指南 - Uber API - POST Request.
StringEntity 参数; 或 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 header 与 - 授权令牌和内容类型..所以不确定我错过了什么..
任何人都可以发现 - 我做错了什么吗?
提前致谢
start_longitude
字段名称后附加了一个空白字符:
"start_longitude "
^ remove this space character
我正在使用 Uber API 并尝试在沙盒中叫车。我正在关注这里的 API 指南 - Uber API - POST Request.
StringEntity 参数; 或 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 header 与 - 授权令牌和内容类型..所以不确定我错过了什么..
任何人都可以发现 - 我做错了什么吗?
提前致谢
start_longitude
字段名称后附加了一个空白字符:
"start_longitude "
^ remove this space character