UberX没有准确的估计价格

2024-04-20 04:00:03 发布

您现在位置:Python中文网/ 问答频道 /正文

目前在应用程序中,请求UberX立即给你一个确切的报价,但在pythonapi中,我找不到它。我只能找到费用的范围。确切的报价在哪里? enter image description here


Tags: 应用程序pythonapi报价费用uberx
1条回答
网友
1楼 · 发布于 2024-04-20 04:00:03

尝试使用“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"

我建议你也使用“产品标识”来获得你需要的产品的价格。否则,如果没有提供,它将默认为给定位置的最便宜产品。你知道吗

你会得到这样的回答:

{
"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。您需要对用户进行身份验证,然后获取要使用的产品,然后获取预付费用(如果产品支持此项:预付费用启用字段设置为true)。在那之后你就可以预订一辆车了。如何做到这一点的代码也在我发送的doc link中:

# 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

相关问题 更多 >