Search code examples
pythontwittertweepy

How to get twitter users screen-name or UserId from a specific geolocations?


I want to get tweets from specific geo-location, so i used tweepy (api.search) method. I am successfully getting tweets from the specific geo location. but I am not getting screen name or userid. I am expecting that show_user when True will return me the screen name, who is posting that tweet. but i am not getting any screen name. so please tell me the solution how can i get the screen name who is posting that tweet by given geo location. Using tweepy.

public_tweets = tweepy.Cursor(api.search, rpp=100, 
geocode="44.269493,63.341332,5km",since="2018-05-01",show_user = 
"True",tweet_mode="extended").items()

Solution

  • rpp is deprecated, use "count" instead (see https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets.html).

    This works with "100km" ("5km" returned no result).

    consumer_key = '***'
    consumer_secret = '***'
    access_token = '***'
    access_token_secret = '***'
    
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
    
    tweets = api.search(count=100,geocode="44.269493,63.341332,5km",since="2018-05-01")
    for tweet in tweets:
        print(tweet.user.id_str, tweet.user.screen_name, tweet.text)