无法将Uber API授权码交换为获取当前行程详细信息的访问令牌


Unable to Exchange Uber API authorization code for an access token for fetching current trip details

一旦优步用户验证并授权我的应用程序,我将收到一个授权代码,但我无法交换access_token的授权代码。

我试图获取当前的旅行信息使用: https://developer.uber.com/docs/trip-experiences/references/api/v1-requests-current-get

// uber.php
echo $_GET['code']."<br>";
$token = curl_init();
$param = array(
    'client_secret' => 'xxxxxxxxxxxxxx',
    'client_id' => '_xxxxxxxxxxxxxxxxxxxxxx',
    'grant_type' => 'authorization_code',
    'redirect_uri' => 'http://localhost/uber/uber.php', // (the same as in app settings)
    'code' => "{$_GET['code']}"
    );
$postData = '';
foreach($param as $k => $v)
    {
       $postData .= $k . '='.urlencode($v).'&';
    }
$postData = rtrim($postData, '&');
curl_setopt($token, CURLOPT_URL, 'https://login.uber.com/oauth/v2/token');
curl_setopt($token, CURLOPT_HEADER, true);
curl_setopt($token, CURLOPT_RETURNTRANSFER, true);
curl_setopt($token, CURLOPT_POST, true);
curl_setopt($token, CURLOPT_POSTFIELDS, $postData);
$returned_token = curl_exec($token);
curl_close($token);
echo "<hr>";
echo $returned_token;
echo "<hr>";

我得到一个空白的输出

添加:

curl_setopt($token, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); 

,问题解决了…: -)

相关文章: