DownloadsDownloadslifecycle

R client for accessing Twitter’s REST and stream APIs. Check out the rtweet package documentation website.

Usage

All you need is a Twitter account and you can be up in running in minutes!

API authorization

All users must be authorized to interact with Twitter’s APIs. To become authorized, follow the instructions below to (1) make a Twitter app and (2) create and save your access token (using one of the two authorization methods described below).

1. Create an app

  • To gain access Twitter’s APIs, first go to apps.twitter.com and create a new app by completing the form fields (note: users must enter the value for Callback URL exactly as it appears below):
    • Name: Name of Twitter app e.g., my_twitter_research_app
    • Description: Describe use case e.g., for researching trends and behaviors on twitter
    • Website: Valid website e.g., https://twitter.com/kearneymw
    • ***Callback URL***: http://127.0.0.1:1410
  • Check yes if you agree and then click “Create your Twitter application”

2a. Authenticate via web browser (interactive)

2b. Authenticate via access token

And that’s it! You’re ready to start collecting and analyzing Twitter data! And because create_token() automatically saves your token as an environment variable, you’ll be set for future sessions as well!

Package features

Search tweets

Search for up to 18,000 (non-retweeted) tweets containing the rstats hashtag.

Quickly visualize frequency of tweets over time using ts_plot().

Twitter rate limits cap the number of search results returned to 18,000 every 15 minutes. To request more than that, simply set retryonratelimit = TRUE and rtweet will wait for rate limit resets for you.

Search by geo-location—for example, find 10,000 tweets in the English language sent from the United States. Note: lookup_coords() requires users have a Google API key

Stream tweets

Randomly sample (approximately 1%) from the live stream of all tweets.

Stream all geo enabled tweets from London for 60 seconds.

Stream all tweets mentioning realDonaldTrump or Trump for a week.

Get favorites

Get the 3,000 most recently favorited statuses by JK Rowling.

jkr <- get_favorites("jk_rowling", n = 3000)

Search users

Search for 1,000 users with the rstats hashtag in their profile bios.

Post actions

  • Posting (tweeting from R console) or reading direct messages require additional permissions
  • If you’d like to post Twitter statuses, follow or unfollow accounts, and/or read your direct messages, you’ll need to create your own Twitter app
  • To create your own Twitter app, follow the instructions in the authorization vignette on obtaining and using access tokens

Contact

Communicating with Twitter’s APIs relies on an internet connection, which can sometimes be inconsistent. With that said, if you encounter an obvious bug for which there is not already an active issue, please create a new issue with all code used (preferably a reproducible example) on Github.