【问题标题】:Uber Rush API SandboxUber Rush API 沙盒
【发布时间】:2016-10-12 07:42:51
【问题描述】:

正在尝试测试 Uber Rush API(来自 localhost 和 linux 服务器)。

调用令牌有效 - 我得到令牌 尝试实现 sanbox 示例:

curl -X "PUT /v1/sandbox/deliveries/{delivery_id}" \
  -H "Authorization: Bearer <OAUTH TOKEN>" \
  -d "{\"status\":\"en_route_to_pickup\"}"

带有网址https://sandbox-api.uber.com/

我用 file_get_contents 尝试了同样的请求(在 PHP 中)

所以,我总是收到错误“405 Method Not Allowed”

{"message":"Method not supported for this endpoint.","code":"method_not_allowed"}

我需要做什么才能从这个沙盒示例https://developer.uber.com/docs/rush/sandbox 访问方法?

正确的语法

curl -X "PUT" -H "Authorization: Bearer <TOKEN>" -H "Content-Type: application/json" -d "{\"status\":\"en_route_to_pickup\"}" https://sandbox-api.uber.com/v1/sandbox/deliveries/DELIVERY_ID

【问题讨论】:

  • 您对 file_get_contents 的确切调用是什么?
  • $url = 'https://sandbox-api.uber.com/v1/sandbox/deliveries/ID_HERE'; $headers = array( 'Authorization: Bearer '.TOKEN_HERE); $options = array( 'https' =&gt; array( 'header'=&gt; $headers , ), ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context);

标签: uber-api


【解决方案1】:

编辑:已更新以反映您的问题中的这两个问题...

您的请求不匹配,并且 curl 的语法不正确。

首先,您的 CURL 请求指定不正确。应该是:

curl -X "PUT" -H "Authorization: Bearer <OAUTH TOKEN>" -d "{\"status\":\"en_route_to_pickup\"}" https://sandbox-api.uber.com/v1/sandbox/deliveries/{delivery_id}

此外,您的 curl 命令正在尝试向 uber sandbox PUT API 发出 PUT 请求。但是,您的 PHP 代码没有正确设置上下文,因此可能发出了 GET 请求。我怀疑服务器因此拒绝请求作为 GET,因为不允许执行此类操作。

要修复它,请参阅Bad request using file_get_contents for PUT request in PHP。这应该为您提供一个示例,说明如何传递必要的上下文以使用 file_get_contents() 发出 PUT 请求。

【讨论】:

  • 为了干净,我已经使用了所有可能的选项来使这个请求工作。这个也有 PUT 方法。 $url = 'sandbox-api.uber.com/v1/sandbox/deliveries/ID_HERE'; $headers = array('授权:承载'.TOKEN_HERE); $options = array( 'https' => array( 'header'=> $headers , 'method' => 'PUT', ), ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context);
  • 我不担心 php 代码,我担心为什么我的方法不允许 curl 命令。我在这里得到这个代码https://developer.uber.com/docs/rush/sandbox
  • @ЕвгенийИванов 如果您的问题是 curl 请求,那只是因为它在语法上不正确。查看我编辑的答案...
  • 谢谢@Peter Prittain,像 "curl -X "PUT" -H "Authorization: Bearer " -H "Content-Type: application/json" -d "{\"状态\":\"en_route_to_pickup\"}" sandbox-api.uber.com/v1/sandbox/deliveries/123"
  • 太棒了!作为最后一步,您可能想告诉 Uber 支持他们的文档是错误的和/或赞成这个答案有帮助......
猜你喜欢
  • 2017-01-02
  • 2015-05-21
  • 1970-01-01
  • 2016-05-17
  • 2015-08-03
  • 2016-09-22
  • 1970-01-01
  • 1970-01-01
  • 2014-10-03
相关资源
最近更新 更多