没有UberX的确切金额估计价格

时间:2018-01-25 14:50:34

标签: python uber-api

目前在应用程序中,请求UberX立即为您提供确切的报价,但在Python API中,我无法找到它。我只能找到成本的范围。确切的报价在哪里? enter image description here

1 个答案:

答案 0 :(得分:3)

尝试使用" POST /v1.2/requests/estimate"

示例请求

curl -X POST \
 -H 'Authorization: Bearer <TOKEN>' \
 -H 'Accept-Language: en_US' \
 -H 'Content-Type: application/json' \
 -d '{
   "start_latitude": 37.7752278,
   "start_longitude": -122.4197513,
   "end_latitude": 37.7773228,
   "end_longitude": -122.4272052
 }' "https://api.uber.com/v1.2/requests/estimate"

我建议您使用&#34; product_id&#34;同样 - 获得您需要的产品的价格。否则,如果没有提供,它将默认为给定位置的最便宜的产品。

您将得到如下响应:

{
"fare": {
"value": 5.73,
"fare_id": "d30e732b8bba22c9cdc10513ee86380087cb4a6f89e37ad21ba2a39f3a1ba960",
"expires_at": 1476953293,
"display": "$5.73",
"currency_code": "USD",
"breakdown": [
 {
   "type": "promotion",
   "value": -2.00,
   "name": "Promotion"
 },
 {
   "type": "base_fare",
   "notice": "Fares are slightly higher due to increased demand",
   "value": 7.73,
   "name": "Base Fare"
 }
 ]
},
"trip": {
"distance_unit": "mile",
"duration_estimate": 540,
"distance_estimate": 2.39
},
"pickup_estimate": 2
}

与Pyton SDK相关 - 请检查:https://developer.uber.com/docs/riders/ride-requests/tutorials/api/python。您需要对您的用户进行身份验证,然后获取您想要使用的产品,然后获得前期票价(如果产品支持:upfront_fare_enabled字段设置为true)。之后,您可以预订车程。代码怎么做是在我发送的doc链接中:

# Get products for a location
response = client.get_products(37.77, -122.41)
products = response.json.get('products')

product_id = products[0].get('product_id')

# Get upfront fare and start/end locations
estimate = client.estimate_ride(
product_id=product_id,
start_latitude=37.77,
start_longitude=-122.41,
end_latitude=37.79,
end_longitude=-122.41,
seat_count=2
)
fare = estimate.json.get('fare')

# Request a ride with upfront fare and start/end locations
response = client.request_ride(
product_id=product_id,
start_latitude=37.77,
start_longitude=-122.41,
end_latitude=37.79,
end_longitude=-122.41,
seat_count=2,
fare_id=fare['fare_id']
)

request = response.json
request_id = request.get('request_id')

# Request ride details using `request_id`
response = client.get_ride_details(request_id)
ride = response.json

# Cancel a ride
response = client.cancel_ride(request_id)
ride = response.json