我如何将下面的curl命令从Lyft api转换为http接口的请求(这样它们就可以像https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY一样在web上执行)?如果无法转换http请求,我如何在R中集成和处理这些curl命令?
#Authentication code
curl -X POST -H "Content-Type: application/json" \
--user "<client_id>:<client_secret>" \
-d '{"grant_type": "client_credentials", "scope": "public"}' \
'https://api.lyft.com/oauth/token'
#Search query
curl --include -X GET -H 'Authorization: Bearer <access_token>' \
'https://api.lyft.com/v1/eta?lat=37.7833&lng=-122.4167'发布于 2017-08-22 14:09:28
您好,您可以使用https://curl.trillworks.com/将curl命令转换为您选择的语言,也可以使用lyft SDK的(对于Python,请使用https://pypi.python.org/pypi/lyft_rides)。
以下是对应的Python版本
import requests
headers = {
'Content-Type': 'application/json',
}
data = '{"grant_type": "client_credentials", "scope": "public"}'
requests.post('https://api.lyft.com/oauth/token', headers=headers, data=data, auth=('<client_id>', '<client_secret>'))从这个post请求中,您将获得访问令牌,该令牌必须用于后续请求。
headers = {
'Authorization': 'Bearer <access_token>',
}
requests.get('https://api.lyft.com/v1/eta?lat=37.7833&lng=-122.4167', headers=headers)注意:我还没有测试过这一点,因为我无法创建lyft开发人员帐户,所以在这里给出的代码中可能会有一些小的改动。
发布于 2017-08-23 01:25:07
完全公开:我是Lyft的开发者倡导者,我对R不是很熟悉,但是你能用这篇博客文章中描述的方法来集成响应/调用吗?
https://www.r-bloggers.com/accessing-apis-from-r-and-a-little-r-programming/
发布于 2020-10-15 02:19:44
ReqBin可以自动将Curl命令转换为HTTP请求
这类请求的一个示例:Convert Curl to HTTP Request
https://stackoverflow.com/questions/45809708
复制相似问题