【问题标题】:How to use the access token from uber api in accessing trip history如何使用来自 uber api 的访问令牌来访问行程历史
【发布时间】:2017-10-20 19:47:55
【问题描述】:

我正在尝试 Uber API 并从具有 Access Token 的 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'

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

【问题讨论】:

  • 现在我们有了你的代币并将使用它们)))))
  • 这应该会有所帮助:stackoverflow.com/questions/2138527/…
  • @u_mulder 请继续使用这些 :-) 这些不是实际的.. 在公开论坛发帖之前,我已经用随机值替换了这些令牌......祝你好运:-)

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


【解决方案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);

【讨论】:

  • 我如何从重定向 uri 中获取 $token 中访问令牌的值,该重定向 uri 返回一个 json 响应,其中包括访问令牌以及其他键和值。
  • 所以你不知道如何处理 json 字符串?看这里stackoverflow.com/questions/29308898/…
  • @u_mulder 我知道解析 json .. 我的意思是包含访问令牌的 json 字符串显示为 url 的响应。我无法在任何变量中捕获该 json 输出。 $data = fetchUrl('login.uber.com/oauth/v2/token', $_GET['code']);返回 json .. 我需要在一个变量中捕获这个 json。获取访问令牌..并传递到下一个 curl
  • 然后请创建一个新问题或编辑这个问题。因为你遇到的问题与现在所描述的完全没有关系。
  • 请使用您尝试过的其他数据或脚本更新您的问题
猜你喜欢
  • 2011-12-10
  • 1970-01-01
  • 2016-07-02
  • 2011-12-11
  • 1970-01-01
  • 2016-02-09
  • 1970-01-01
  • 1970-01-01
  • 2023-04-01
相关资源
最近更新 更多