0

我遇到了一个我正在努力修复的错误。当使用沙盒环境(以及服务器访问令牌)向https://api.lyft.com/v1/rides发出发布请求时, 我看到以下响应:

{
    "error_detail":[
        {"origin.lat":"Missing required parameter"},
        {"origin.lng":"Missing required parameter"}],
        "error":"bad_parameter"
}

这表明缺少这两个参数。但是,这些参数包含在我的请求中:

{
    "method":"POST",
    "form":{
            "ride_type":"lyft",
            "origin":{
                    "lat":"37.773972",
                    "lng":"-122.431297"
            },
            "destination":{
                    "lat":"37.6213129",
                    "lng":"-122.3789554"
            }
    },
    "url":"https://api.lyft.com/v1/rides",
    "href":"https://api.lyft.com/v1/rides",
    "pathname":"",
    "headers":{
        "Content-Type":"application/json",
        "Authorization":"Bearer THE-SERVER-ACCESS-TOKEN-MADE-WITH-SANDBOX-PREFIX"
    }
}

或者,服务器有时会回复说ride_type 丢失了,但实际上没有。

有人可以告诉我我在这里缺少什么吗?我正在使用带有请求库的 NodeJs 服务器

4

1 回答 1

0

I haven't used the node request library extensively, but it might have something to do with your json not getting serialized to the level of depth you need. Have you tried using axios? It's a really popular http api that might clear up your errors. Your request would look like this:

axios.post('https://api.lyft.com/v1/rides', {
  ride_type: 'lyft',
  origin: {
    lat: '37.773972',
    lng: '-122.431297'
  },
  destination: {
    lat: '37.6213129',
    lng: '-122.3789554'
  }
}, {
  headers: {
    Authorization: 'Bearer <access_token>'
  }
})
.then(succ => console.log(succ.data))
.catch(err => console.log(err))
于 2018-05-21T16:49:42.930 回答