Accessing Data from Twitter API using R

Michael Galarnyk
Jan 24, 2017 · 2 min read

UPDATE: An updated version of this tutorial can be found here.

Using the Twitter API should be an easy thing, but sometimes pictures and simple code can save you that extra 5 minutes. With that, this post goes over how to use the Twitter API to get tweets using R.

First we need Twitter API Access. The following steps will help you set up your twitter account and be able to use the Twitter API.

  1. Create a twitter account if you do not already have one.
  2. Go to and log in with your twitter credentials.

3. Click “Create New App”

Click on Create New App.

4. Fill out the form and agree to the terms. Click on Create your Twitter application. Put your Callback URL as http://localhost:1410.

Create your Twitter application

5. On the next page, click the “Keys and Access Tokens” tab along the top, then scroll all the way down until you see the section “Your Access Token”

Click on Keys and Access Tokens

6. Click the button “Create My Access Token”.

Click on Create my access token

7. You should have a screen like the following below.

FYI Dont share your keys or access token. These keys and tokens used in this tutorial no longer exist.

8. Finally we actually get to use the API to get data. Using the following code below, we can get twitter data.

The twitteR package makes accessing data very easy

Note: The reason why we supply the access_token and access_secret is described in the setup_twitter_oauth .Rd file.

Please let me know if you have any questions! You can either leave a comment here, on youtube or Twitter.

Michael Galarnyk

Written by

Data Scientist at Scripps Research Institute

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade