Search code examples
pythontweets

filter tweets by location using client tweepy latest version


import tweepy as tw

client = tw.Client(bearer_token='')

I want to filter the tweet data using a location search query that I found from twitters client API docs.

I tried using bounding_box as a filter location but it just outputs an error every time I use it There were errors processing your request: no viable alternative at input '119.19,4.94,127.31,19.38'

query = 'crypto -is:retweet bounding_box:[119.19,4.94,127.31,19.38]'

for tweet in tw.Paginator(client.search_recent_tweets, query=query, 
tweet_fields=[ 'created_at'], max_results=100).flatten(limit=1000):

    print(tweet.text, tweet.created_at)

is there a possible way of filtering the tweet data by location?


Solution

  • Replace commas with spaces:

    query = 'crypto -is:retweet bounding_box:[119.19 4.94 127.31 19.38]'
    

    ..as is stated in Twitter API docs:

    bounding_box:[west_long south_lat east_long north_lat]

    Example: bounding_box:[-105.301758 39.964069 -105.178505 40.09455]

    Rule arguments are contained within brackets, space delimited.