我正在使用python 3.6.4。尝试使用以下方法从Survey Monkey API检索数据:
access_token = 'xxx'
collector_id = 'yyy'
s = requests.session()
s.headers.update({
"Authorization": "Bearer %s" % access_token,
"Content-Type": "application/json"
})
url = "https://api.surveymonkey.com/v3/collectors/%s/responses/bulk?start_created_at=2020-
02-11T23:20:00+00:00" % (collector_id)
res = s.get(url)
dat = res.json()
不幸的是,这导致以下错误:
{'error': {'id': '1003',
'name': 'Bad Request',
'docs': 'https://developer.surveymonkey.com/api/v3/#error-codes',
'message': 'Invalid URL parameters.',
'http_status_code': 400}}
我找到了一个帖子,解决了与此处相同的问题,但是那里提供的解决方案对我不起作用。这是帖子:start_created_at not working with /collectors/{id}/responses
有人可以指出正确的方向,说明如何设置查询字符串的格式,以便我要过滤的URL参数有效?
您只需要对URL的日期/时间部分进行URL编码。试试这个:
timedate = '2020-02-11T23:20:00+00:00'
timedate_enc = urllib.parse.quote(timedate)
url = 'https://api.surveymonkey.com/v3/collectors/%s/responses/bulk?start_created_at=%s' % (collector_id, timedate_enc)