Search code examples
phpcurluber-api

Uber Api GET /me using Curl is not working


I am trying to implement Uber Api GET /me

Ref :- https://developer.uber.com/docs/riders/references/api/v1.2/me-get

They specified that :- Replace <TOKEN> in the example below with a user access token    

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

I have write the above code in curl, but I am always getting "Error":"No authentication provided.","code":"unauthorized"

My Curl code is

<?php

    // Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://api.uber.com/v1.2/me");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");


    $headers = array();
    $headers[] = "Authorization: Bearer <token>";       #<token> has been replaced by my 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);

I am always getting "Error":"No authentication provided.","code":"unauthorized"

Still this is not working. Is Uber Api stops working today ?

Solution

  • Based on research, finally I am able to get the solution.Uber returns

    get
    https://sandbox-api.uber.com/v1.2/me
    
    Array
    (
        [0] => Authorization: Token <My token>
        [1] => Accept-Language: en_US
        [2] => Content-Type: application/json
    )
    {"error":true,"message":"We have experienced a problem.","code":500,"content":null}
    

    So Uber is having issue. Wasted a lot of time