Reputation: 177
I am trying to make a GET request to the Uber API using my personal access token (which is generated on the developer dashboard page). When I execute the request with my SERVER TOKEN, as shown below, I get a response.
headers = {'Authorization' : 'Token '+server_token}
payload = {'latitude' : start_lat,
'longitude' : start_lon}
r = requests.get(base_url + products_urn, params = payload, headers = headers)
print r.url
print r.json()
The result of this code is:
https://api.uber.com/v1.2/products?latitude=40.53&longitude=-80.17
{u'products': [{u'upfront_fare_enabled': True, u'capacity': ...
When I try to use my personal access token, by changing
headers = {'Authorization' : 'Token '+server_token}
to
headers = {'Authorization' : 'Bearer '+access_token}
(Which is what the API docs say to do to use an access_token) The result is then:
https://api.uber.com/v1.2/products?latitude=40.53&longitude=-80.17
{u'message': u'No authentication provided.', u'code': u'unauthorized'}
I realize I don't need an access token to get to the 'product' endpoint, I'm just using it as an example.
What is the proper way to make an Uber API request using the personal access token?
I'm new to the API game, any help is welcome, thank you!
Upvotes: 1
Views: 613
Reputation: 161
This authorization failure can be received when access token isn't entered properly. From this side it seems that API call is well-formed, so please check out the access token entry.
Please check out this piece of curl code:
curl -H 'Authorization: Bearer <ACCESS_TOKEN>' \
-H 'Accept-Language: en_US' \
-H 'Content-Type: application/json' \
'https://sandbox-api.uber.com/v1.2/products?latitude=40.53&longitude=-80.17'
This would make proper response for API call. Also, check out that url for API call is https://sandbox-api.uber.com. Please, use this url for all your API tests, cause this environment is made for testing purposes only, instead of production environment.
All the best,
Upvotes: 2