Tweepy地理搜索使返回的tweet远远超出范围

问题描述 投票:0回答:1

请帮助!我正在尝试使用免费的tweepy API完成特定于地理位置的查询搜索。我意识到返回的推文坐标/位置仍然来自全球。即使我简化了代码以进行调查,地理位置仍然无法正常工作:

# 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英里的孟加拉国中搜索,则会返回带有来自美国的地方的地点/坐标的推文。

任何帮助将不胜感激!

python api geolocation tweepy tweets
1个回答
0
投票

我认为您的地理位置参数已被忽略。传递给搜索api的参数名称为geocode,而不是geo。试试这个:

results = api.search(q=query, geocode=gg, count=100)

[当我以最小10 km的搜索半径运行时,没有任何结果。如果我将半径扩大到1000公里,我会得到更多。

参考: API.search

© www.soinside.com 2019 - 2024. All rights reserved.