Uber Api在php localhost上返回401

时间:2019-02-12 08:21:57

标签: php oauth-2.0 uber-api

我在这里有一个问题,我简直无法得到超级退货,除了

我已经激活了Uber Dashboard上创建的应用程序中的所有作用域(甚至是受限访问权限),并允许通过POSTMAN访问该应用程序

{"code":"unauthorized","message":"Invalid OAuth 2.0 credentials provided."}

重定向URI到我使用以下代码的本地主机:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://sandbox-api.uber.com/v1.2/me"); //v2 does not work for some reason
//curl_setopt($ch, CURLOPT_URL, "https://api.uber.com/v1.2/me"); //i used this aswel, same thing happens
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");


$headers = array();
$headers[] = "Authorization: Bearer ".$_GET['code'];       #$_GET['code'] has been replaced by my oauth2 token

$headers[] = "Accept-Language: en_US";
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
echo "<pre>";
print_r($headers);

$result = curl_exec($ch);

$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo "<li>".$httpcode;
echo "<pre>";print_r($result);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);

这是我从上面的代码中得到的答复:

Array
(
[0] => Authorization: Bearer auth-token-from-get //please let me know if i made the header correctly
[1] => Accept-Language: en_US
[2] => Content-Type: application/json
)
401

{"code":"unauthorized","message":"Invalid OAuth 2.0 credentials provided."}

请在这里给我一个提示吗?我到处寻找解决方案,真的很难找到

0 个答案:

没有答案