pacman::p_load(tidyverse)

Overview

Apply for a developer account

Create a project

Authenticate with R

:::{.tip} Note you will need to complete the following steps on a local machine. You cannot create an authentication token in RStudio Cloud. Refer to this guide to install R and RStudio on your own computer. :::

Only if you plan on pushing this project to GitHub:

Continue with the following steps:

library(rtweet)
## stored api keys 
# (these are fake example values; replace with your own keys)
app_name <- "project_francom"
api_key <- "afYS4vbIlPAj096E60c4W1fiK"
api_secret_key <- "bI91kqnqFoNCrZFbsjAWHD4gJ91LQAhdCJXCj3yscfuULtNkuu"

## authenticate via web browser
token <- create_token(
  app = app_name,
  consumer_key = api_key,
  consumer_secret = api_secret_key)

You will now have a token saved in your R Project environment for use.

:::{.tip} If you want to use this token on RStudio Cloud, you will need to first save token as an .rds file.

saveRDS(token, file = "~/Desktop/token.rds")

Then you will upload it to the RStudio Cloud project where you want to interface with the Twitter API.

To use the token, read the token.rds file and assign it to an object.

token = readRDS("token.rds")

Use this object name (token) in your calls to rtweet functions (token = token).

One final note, if you plan to push your project to GitHub include the name of the .rds token file in .gitignore to that it is not made public. :::



francojc/tadr documentation built on April 26, 2022, 7:55 p.m.