在Uber API中请求产品时出错

时间:2016-10-05 03:10:37

标签: node.js uber-api

我在node.js中请求/ v1 / products获取特定区域中可用的汽车列表,但我得到了这个:

{"fields":{"latitude":"Required","longitude":"Required"},"message":"Invalid request","code":"validation_failed"}

代码:

var https = require('https');

var data = {
    'latitude': '37',
    'longitude': '-122',
};

data = JSON.stringify(data);

var options = {
    host: "api.uber.com",
    path: "/v1/products",
    method: "GET",
    headers: {
        "Content-Type": "application/json",
        "Authorization": "Token myAppToken",
        "Content-Length": Buffer.byteLength(data)
    }
};

var req = https.request(options, function(res) {
    var responseString = "";

    res.on("data", function(data) {
        responseString += data;
    });
    res.on("end", function() {
        console.log(responseString);
    });
});

req.write(data);
req.end();

1 个答案:

答案 0 :(得分:1)

您是否以他们指定的格式发布了真实的纬度和经度?更新具有实际纬度和经度的代码。

我会重新使用优步推荐https://github.com/shernshiou/node-uber的模块,然后密切关注这个例子。