我正在尝试使用30天或Twitter的完整存档数据来提取特定位置周围的推文。为此,我使用的是TwitterAPI库,但是在限制位置时仍然出现错误。
from TwitterAPI import TwitterAPI
api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret)
PRODUCT = '30day'
LABEL = 'development'
SEARCH_TERM = 'JFK'
r = api.request('tweets/search/%s/:%s' % (PRODUCT, LABEL),
{'query':SEARCH_TERM, 'point_radius':'[-73.7781 40.6413 2km]'})
for item in r:
print(item['text'] if 'text' in item else item)
我总是遇到相同的错误,但我无法弄清楚我在做什么错。
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Users/Fil/PycharmProjects/Twitter/importtweets.py
Traceback (most recent call last):
File "/Users/Fil/PycharmProjects/Twitter/importtweets.py", line 18, in <module>
for item in r:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/TwitterAPI/TwitterAPI.py", line 219, in __iter__
return self.get_iterator()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/TwitterAPI/TwitterAPI.py", line 206, in get_iterator
raise TwitterRequestError(self.response.status_code)
TwitterAPI.TwitterError.TwitterRequestError: Twitter request failed (422)
Process finished with exit code 1
答案 0 :(得分:2)
query
必须放在SEARCH_TERM = 'JFK point_radius:[-73.7781 40.6413 2km]'
值内。试试:
const square = document.querySelector(".square");
const colors = ["blue", "red", "green", "yellow", "orange", "cyan", "purple", "teal", "brown"];
square.addEventListener("click", function () {
const chooser = colors[Math.floor(Math.random() * colors.length)];
document.getElementById("color").style.backgroundColor = chooser;
})