3

I am trying to create a timeline of tweets for a specific hashtag according to geographic location. The location should be a country.

I would like to verify if my code below indeed filters the tweets by country (in this case France):

tag=„NBA"
# determine place id corresponding to country coordinates
      geo=GET("https://api.twitter.com/1.1/geo/search.json?query=France&granularity=country",
      config(token = twitter_token))
      geo <- content(geo, as = "text")
      geo=fromJSON(geo)
      country_id= geo$result$places$id
# use id to filter tweets by country
      req=GET(sprintf("https://api.twitter.com/1.1/search/tweets.json?q=%%23%s&src=typd&count=100&id=%s",
                  tag, country_id),
          config(token = twitter_token))
      req <- content(req, as = "text")
      newTweets=fromJSON(req)

Is this the way to go?

What I find somewhat puzzling is that according to...

https://dev.twitter.com/rest/reference/get/search/tweets

...there is only the possibility to set option geocode but nothing is mentioned regarding place_id

kanimbla
  • 858
  • 1
  • 9
  • 23
  • You can search by place using [search-by-place](https://dev.twitter.com/rest/public/search-by-place). Also, take a look to this [SO question](http://stackoverflow.com/questions/17633378/how-can-we-get-tweets-from-specific-country), it is not R but should be easy to translate. – lrnzcig Jul 17 '15 at 09:37
  • Thanks for your comment. The search-by-place option does not allow you to filter tweets for a given hashtag by place (this just allows you to search for tweets, which mention a certain place). After doing some more research on the issue I believe that Twitter does not allow searching systematically for hashtag/tweets in a specific country: therefore, the above piece of code does not work as intended. One alternative solution would be to look at results according to user location, i.e. in the above case `newTweets$statuses$user$location` – kanimbla Jul 20 '15 at 16:14

0 Answers0