2016-06-11 67 views
1

试图测试Uber Rush API(从本地主机和从Linux服务器)。Uber Rush API Sandbox

呼叫标记的工作 - 我得到的令牌 试图实现的SANbox例如:

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

与URL https://sandbox-api.uber.com/

,我试着用的file_get_contents(在PHP)

所以相同的请求,我总是得到错误“405方法不允许”

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

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

Corrent语法

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 
+0

你正在做什么确切的调用file_get_contents? –

+0

'$ url ='https://sandbox-api.uber.com/v1/sandbox/deliveries/ID_HERE'; $ headers = array('Authorization:Bearer'.TOKEN_HERE); $ options = array( 'https'=> array( 'header'=> $ headers, ), ); $ context = stream_context_create($ options); $ result = file_get_contents($ url,false,$ context);' –

回答

0

编辑:更新你的问题,以反映这两个问题...

您的要求不匹配和卷曲的不正确的语法。

首先您的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命令试图发出PUT请求uber sandbox PUT API。但是,您的PHP代码不能正确设置上下文,因此可能会发出GET请求。因此,我怀疑服务器因为不允许进行这种操作而将请求拒绝为GET。请参阅Bad request using file_get_contents for PUT request in PHP。这应该给你一个例子,说明如何通过必要的上下文来使用file_get_contents()来发出PUT请求。

+0

为了干净,我使用了所有可能的选项来使这个请求有效。这也与方法PUT一样。 $ url ='https://sandbox-api.uber.com/v1/sandbox/deliveries/ID_HERE'; $ headers = array('Authorization:Bearer'.TOKEN_HERE); $选项=阵列( 的 'https'=>数组( '标题'=> $标头, '方法'=> 'PUT', ) ); $ context = stream_context_create($ options); $ result = file_get_contents($ url,false,$ context); –

+0

我不担心php代码,我担心为什么我不能在curl命令上使用方法。我在这里得到这个代码[https://developer.uber.com/docs/rush/sandbox](https://developer.uber.com/docs/rush/sandbox) –

+0

@ЕвгенийИванов如果你的问题是curl请求,这只是因为它在语法上不正确。看到我编辑的答案... –