簡體   English   中英

Tweepy 地理搜索不斷返回超出范圍的推文

[英]Tweepy geo search keeps returning tweets far outside of range

請幫忙。 我正在嘗試使用免費的 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 英里的孟加拉國進行搜索,則會返回來自遠至美國的地點/坐標的推文。

任何幫助將非常感激!

我認為您的地理參數被忽略了。 傳遞給搜索 api 的參數名稱是geocode ,而不是geo 嘗試這個:

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

當我以小至 10 公里的搜索半徑運行它時,我沒有得到任何結果。 如果我將半徑擴大到 1000 公里,我會得到更多。

參考: API.search

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM