2

I am trying the Uber API and have got the following response output from the Uber API which has the Access Token :

{"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"}

Next I want to use CURL as mentioned below to access the trip history which is documented at : 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'

but I am unsure on how or where to set the access token for the curl request which will respond with the trip history as json output.

Sandy505
  • 858
  • 2
  • 15
  • 26
  • Now we have your tokens and will use them))))) – u_mulder May 20 '17 at 21:53
  • This should help: http://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code – Marc May 20 '17 at 21:56
  • @u_mulder Please go ahead and use these :-) these are not the actual ones.. i had replaced these tokens with random values before posting in open forum... Best of Luck :-) – Sandy505 May 21 '17 at 07:43

1 Answers1

1

Try to using curl to php converter from here https://incarnate.github.io/curl-to-php/

here is the result

$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);
rheeantz
  • 862
  • 7
  • 12
  • How do i get the value of access token in $token from the redirect uri which returns a json response which includes access token apart from other key and values also.. – Sandy505 May 21 '17 at 07:57
  • So you don't know how to work with json strings? Look here http://stackoverflow.com/questions/29308898/how-do-i-extract-data-from-json-with-php – u_mulder May 21 '17 at 08:03
  • @u_mulder i know about parsing json.. My point is that the json string which contains the access token is shown as response by the url. I am unable to capture that json output in any variable. $data = fetchUrl('https://login.uber.com/oauth/v2/token', $_GET['code']); returns the json.. I need to capture this json in a variable. get the acess token .. and pass on to the next curl – Sandy505 May 21 '17 at 08:17
  • 1
    Please then create a new question or edit this one. Because the problem you encounter has nothing with what's described in question now. – u_mulder May 21 '17 at 08:39
  • please update your question with additional data or scripts you tried – rheeantz May 21 '17 at 09:47