Uber API: request_ride with sandbox_mode=True 抛出错误信息

Uber API: request_ride with sandbox_mode=True is throwing error message

request_ridesandbox_mode=True 正在抛出错误消息。以下是我的代码和整个错误消息。

#Python 3.x
from uber_rides.session import Session
from uber_rides.client import UberRidesClient
session = Session(server_token="something-special")
client = UberRidesClient(session,sandbox_mode=True)
#UberX product id
product_id = '04a497f5-380d-47f2-bf1b-ad4cfdcb51f2' 
response = client.request_ride(product_id, 37.77, -122.41, 37.79, -122.41)
ride_details = response.json
ride_id = ride_details.get('request_id')
response = client.update_sandbox_ride(ride_id, 'accepted')
print(response)

#error message
...
...
uber_rides.errors.ClientError: The request contains bad syntax or   
cannot be filled due to a fault from the client sending the request.

您收到 4XX ClientError,因为您正尝试使用服务器令牌请求乘车。如果您处理错误并检查它,您会看到它是 401: Unauthorized error.

要叫车,您需要获得范围为 request 的 OAuth2 访问令牌。

服务器令牌可以访问产品、时间估算和价格估算等端点。要访问更多受保护的资源,例如用户 Activity 或请求端点,您需要遵循 OAuth2 到 get an access token.

Uber 的 Python SDK 中也有一个 OAuth2 Authorization example