pacman::p_load(tidyverse)
http://127.0.0.1:1410https://twitter.com/jrad_cole):::{.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. :::
_twitter_auth.ROnly if you plan on pushing this project to GitHub:
.gitignore_twitter_auth.R to the listContinue with the following steps:
_twitter_auth.R filelibrary(rtweet)
create_token() function. ## 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.
:::
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.