rtweet

This vignette covers how to obtain and use Twitter API access tokens for use in the rtweet package.

Creating a Twitter App

  • To create a Twitter app, navigate to apps.twitter.com and create a new app by providing a Name, Description, and Website of your choosing (example screenshot provided below).

  • Important In the Callback URL field, make sure to enter the following: http://127.0.0.1:1410

  • Check yes if you agree and then click “Create your Twitter application”.

creating

Authorization methods

Users can create their personal access token in two different ways. Each method is outlined below.

1. Browser-based authentication

  • Authentication via web browser requires the httpuv package to be installed.
  • Click the tab labeled Keys and Access Tokens to retrieve your keys.

created

  • In the Keys and Access Tokens tab, locate the values Consumer Key (aka “API Key”) and Consumer Secret (aka “API Secret”).

keys

  • Copy and paste the two keys (along with the name of your app) into an R script file and pass them along to create_token().
  • A browser window should pop up. Click to approve (must be signed into twitter.com) and return to R.

  • The create_token() function should automatically save your token as an environment variable for you. To make sure it worked, compare the created token object to the object returned by get_token()

2. Access token/secret method

  • Click the tab labeled Keys and Access Tokens to retrieve your keys.

created

  • In the Keys and Access Tokens tab, locate and copy/paste values Consumer Key (aka “API Key”) and Consumer Secret (aka “API Secret”) into an R script.

keys

  • In the Keys and Access Tokens tab, scroll down to Token Actions and click Create my access token.

gen_token

  • That should generate two access keys Access Token and Access Token Secret

acesskeys

  • Locate and copy/paste the Consumer Key (aka “API Key”), Consumer Secret (aka “API Secret”), Access Token, and Access Token Secret values and pass them along to create_token(), storing the output as a token object.
  • The create_token() function should automatically save your token as an environment variable for you. To make sure it worked, compare the created token object to the object returned by get_token()

That’s it!