如何使用uber api中的访问令牌访问旅行历史记录

时间:2017-05-20 21:41:13

标签: php json curl oauth-2.0 uber-api

我正在尝试使用 Uber API 并从Uber API获得以下响应输出,其中包含访问令牌

{"last_authenticated":0,"access_token":"KQ.eyJ2ZXJzaW9uIjoyLCJpZCI6IlpOTjJ0ZjVMUzFpcW5JbVEvAdffgfgmc9PfsfsZXNffsdfdsfsdf5MDY4OTEsaW5lX2tleV9pZCI6Ik1RPT0iLCJwaXfCI6MX0.i3fnzPo61qO29IyOcs5OqfqQ_KEYtxs","expires_in":2592000,"token_type":"Bearer","scope":"history history_lite places profile ride_widgets","refresh_token":"QrerwerwrSAsdgdgg5532ADPkOmzXEiATEoATIBMQ.skNozSMCJobAl_vTDfPo2GEi_D0h1daHm6YQXCwgCws.t-NMldx56v2Pe1J_sNTxrNqjBlfsfsdfsfs6Lq8QxT29FM"}

接下来我想使用下面提到的CURL来访问行程历史记录,记录在:https://developer.uber.com/docs/riders/references/api/v1.2/history-get

curl -H 'Authorization: Bearer <TOKEN>' \
     -H 'Accept-Language: en_US' \
     -H 'Content-Type: application/json' \
     'https://api.uber.com/v1.2/history'

但我不确定如何或在哪里设置卷曲请求的访问令牌,它将以json输出的行程历史作为响应。

1 个答案:

答案 0 :(得分:1)

尝试从这里使用curl到php转换器https://incarnate.github.io/curl-to-php/

这是结果

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.uber.com/v1.2/history");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");


$headers = array();
$headers[] = "Authorization: Bearer ".$token;
$headers[] = "Accept-Language: en_US";
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); //For https
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);//For https
$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);


print_r($result);