Search code examples
rrtweet

Does the rtweet library have a way to fetch tweets from a specific location?


I am trying to get tweets that were tweeted from a specific location e.g. 'LA' using the rtweet package. I know the twitteR package used to have something of the sort like:

a<-searchTwitter("sydney", n=100, geocode='-33.871841,151.206709, 10000mi')

where you could even specify the radius.

Is there a way to do add that functionality to the rtweet stream?


Solution

  • From rtweet:

    library(rtweet)
    rt <- search_tweets(
      "lang:en", geocode = lookup_coords("usa"), n = 10000
    )
    

    Stream example from the help page:

    stream_tweets(
      "realdonaldtrump,trump",
      timeout = 60 * 60 * 24 * 7,
      file_name = "tweetsabouttrump.json",
      parse = FALSE,
      lookup_coords("usa")
    )
    

    But you'll need a Google Maps API Key for lookup_coords (See here).

    More here and here.