How to get tweets of a particular hashtag in a location in a tweepy?

倖福魔咒の 提交于 2019-12-05 19:48:30

问题


I wish to obtain tweets of a particular hashtag from a a particular location say Chennai for analysing data. I'm really new to Twitter API and tweepy. I found that the search url would look like this : https://api.twitter.com/1.1/search/tweets.json?q=%23cricket&geocode=-22.912214,-43.230182,1km&lang=pt&result_type=recent

How do the same in tweepy ? Code so far :

import tweepy

ckey = ""
csecret = ""
atoken = ""
asecret = ""

OAUTH_KEYS = {'consumer_key':ckey, 'consumer_secret':csecret,
 'access_token_key':atoken, 'access_token_secret':asecret}
 auth = tweepy.OAuthHandler(OAUTH_KEYS['consumer_key'], OAUTH_KEYS['consumer_secret'])
api = tweepy.API(auth)

cricTweet = tweepy.Cursor(api.search, q='cricket').items(10)

for tweet in cricTweet:
   print tweet.created_at, tweet.text, tweet.lang

回答1:


You need to use the geocode parameter in Tweepy. Using the lat/long/radius from your search URL, your cursor should be defined like so:

tweepy.Cursor(api.search, q='cricket', geocode="-22.9122,-43.2302,1km").items(10)

See the Tweepy API.search documentation for more information on the parameters you can include in your search.



来源:https://stackoverflow.com/questions/27243819/how-to-get-tweets-of-a-particular-hashtag-in-a-location-in-a-tweepy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!