Wednesday, April 29, 2015

Repost: R's twitteR and Accessing the 1 Percent of Geotagged Tweet

About 1 percent of all tweets are geotagged.  Fortunately, most of these geotagged tweets fall into public stream data.

Of course, this only applies to Twitter.  The percent of geotagged media varies by social network source.  For example, Instagram had up to 25% of photos geotagged by users in 2012, according to the New York Times.

We will take a look at the twitteR package in R that provides an interface with the Twitter API. The main reason I chose this was my familiarity with R.

Getting a Twitter Dev Account
First, head over to  You can use your regular Twitter account to login. Click on the "Create New App" button in the upper right-hand corner.  Follow the on-screen instructions and be sure to read the Developer Agreement.

After your "app" is created, click on the "Permissions" tab and make sure the last radio button is selected: "Read, Write, and Access direct messages."  Also check out the Keys and Access Token, especially if you are more familiar with connecting to APIs.

Connecting with R
For this blog, I am using R 3.1.3 64-bit.  Start R, then follow the instructions located in the screenshot below. Click the screenshot for a closer look.
Click the above screenshot to get a closer look.

Update #1 12/10/2015:
In addition to the code listed above, you will have to install one additional package:

Otherwise, you will oauth errors.

Concluding remarks...
Connecting to and using an API may not be your strong suit, but it is not mine either!  Hopefully, I've saved you some time and got you connected to this valuable source of data!

You can also now follow me on Twitter at: @jontheepi.  I will post blog updates there as well as additional quick insights about open source GIS and mapping.

No comments:

Post a Comment