python - Tweepy 地理搜索不断返回超出范围的推文
问题描述
请帮忙!我正在尝试使用免费的 tweepy API 完成特定于地理的查询搜索。我意识到返回的推文坐标/地点仍然来自全球各地。即使我简化代码进行调查,geo 仍然无法工作:
# Get auth - deleter is a function I made to format .txt into string, note the appauth not oauth.
def startup(loc):
consumer_secret = deleter(open(loc[0],'r').read(),'\n')
consumer_key = deleter(open(loc[1],'r').read(),'\n')
auth = tweepy.AppAuthHandler(consumer_key, consumer_secret)
api = tweepy.API(auth, wait_on_rate_limit=True,
wait_on_rate_limit_notify=True)
if (not api):
print ("Can't Authenticate"),sys.exit(-1)
return api
# Keys
loc = ['consumer_scret.txt', 'api.txt']
api = startup(loc)
# Search parameters
query = "lockdown"
gg = "5.29126,52.132633,10km"
results = api.search(q=query,geo=gg, count = 100)
for tweet in results:
print(tweet.id,tweet.geo,tweet.place,tweet.coordinates)
- 无论搜索半径多小,总是返回 100 条推文
- 如果我在半径为 10 英里的孟加拉国进行搜索,则会返回来自远至美国的地点/坐标的推文。
任何帮助将非常感激!
解决方案
我认为您的地理参数被忽略了。传递给搜索 api 的参数名称是geocode
,而不是geo
。尝试这个:
results = api.search(q=query, geocode=gg, count=100)
当我以小至 10 公里的搜索半径运行它时,我没有得到任何结果。如果我将半径扩大到 1000 公里,我会得到更多。
参考: API.search
推荐阅读
- docker - 从第二个参数访问 docker ENTRYPOINT ( exec ) 中的环境变量值(使用 customerentrypoint 脚本作为第一个参数)
- php - Php 有没有办法从数组中弹出最后一个元素并将其放在开头?
- matlab - Matlab,迭代中的连接问题?我如何解决它?
- c - 如何修复 C 中的分段错误(核心转储)错误
- java - HSQLDB:REPLACE INTO 表抛出 org.hsqldb.HsqlException:完整性约束违规:
- firebase - Flutter Firestore 文档快照监听器
- ruby - install_package 的分配分支条件太高
- excel - 执行此复制循环时出现名称冲突错误?
- android - 这个 android 菜单的名称是什么以及如何实现它
- python - 当我运行此代码来编写文本文件时,它并没有像在我的 powershell 上那样整齐地列出它