我正在尝试使用带有 webapp2 的 python 和谷歌应用引擎向 Health Graph API 发出 POST 请求。我已经看到一个示例,其中的操作如下:
payload = {'grant_type': 'authorization_code',
'code': code,
'client_id': 'xxxxxxxxxxxxxxxxxxxxxxx',
'client_secret': 'xxxxxxxxxxxxxxxxxxxxxx',
'redirect_uri': redirect_uri,}
req = requests.post(API_ACCESS_TOKEN_URL, data=payload)
但我似乎无法使用谷歌应用引擎中的请求模块。有没有简单的方法可以做到这一点?
最佳答案
您需要在 Appengine 上使用 Google 的 URL Fetch 库。试试这个:
payload = {'grant_type': 'authorization_code',
'code': code,
'client_id': 'xxxxxxxxxxxxxxxxxxxxxxx',
'client_secret': 'xxxxxxxxxxxxxxxxxxxxxx',
'redirect_uri': redirect_uri}
result = urlfetch.fetch(url=API_ACCESS_TOKEN_URL, payload = payload, method=urlfetch.POST)
关于python - 如何在 python 和 webapp2 中发出 POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19102927/