一种方法是使用twitter geo search API,获取地点id,然后使用place:place_id
执行常规搜索。例如,使用tweepy:
import tweepy
auth = tweepy.OAuthHandler(..., ...)
auth.set_access_token(..., ...)
api = tweepy.API(auth)
places = api.geo_search(query="USA", granularity="country")
place_id = places[0].id
tweets = api.search(q="place:%s" % place_id)
for tweet in tweets:
print tweet.text + " | " + tweet.place.name if tweet.place else "Undefined place"
另请参见这些线程:
UPD(使用相同的例子中的python-twitter上):
from twitter import *
t = Twitter(auth=OAuth(..., ..., ..., ...))
result = t.geo.search(query="USA", granularity="country")
place_id = result['result']['places'][0]['id']
result = t.search.tweets(q="place:%s" % place_id)
for tweet in result['statuses']:
print tweet['text'] + " | " + tweet['place']['name'] if tweet['place'] else "Undefined place"
希望有所帮助。
多数民众赞成在一个非常好的主意,将尝试此..非常感谢你 – user2490790
有没有办法做同样的事情,但与python-twitter包装? – user2490790
当然,我已经添加了一个例子。请检查。 – alecxe