"Unable to parse JSON" 来自优步的错误 API

"Unable to parse JSON" error from Uber API

(类似问题但不同 language/implementation - Uber API - requests endpoint cannot read read json)

我在尝试向 UBER API 的 /v1/requests 端点发出 post 请求时收到以下错误 API。

{"message":"Unable to parse JSON in request body.","code":"invalid_json"}

这是我的代码:

response = access_token.post('https://sandbox-api.uber.com/v1/requests', {params: {:start_latitude => 37.761492, :start_longitude => -122.423941, :end_latitude => 37.775393, :end_longitude => -122.417546}, :headers => {'Content-Type' => 'application/json'}})

如您所见,我正在使用 [oAuth2 gem][1] 进行 API 调用。我如何设置查询格式以使 JSON 为 API 所接受?我似乎找不到任何说明这一点的文档。

如有任何帮助,我们将不胜感激。谢谢。

看来您没有正确使用 oauth2 gem。查看此问题的最佳答案 Ruby on Rails: how to use OAuth2::AccessToken.post?

body 参数用于 POST 的正文。您正在使用 params 用于查询参数。