knitr::opts_chunk$set(echo = TRUE, eval = FALSE, comment = "#>", collapse = TRUE)
This vignette covers how to obtain and use Twitter API access tokens for use in the rtweet
package.
To create a Twitter app, you will first need to apply for a developer account. This process along with a detailed explanation can be found at developer.twitter.com.
Once you have acquired a developer account, navigate to developer.twitter.com/en/apps, click the blue button that says, Create a New App
, and then complete the form with the following fields:
App Name
: What your app will be calledApplication Description
: How your app will be described to its users
Website URLs
: Website associated with app–I recommend using the URL to your Twitter profileCallback URLs
: IMPORTANT enter exactly the following: http://127.0.0.1:1410
Tell us how this app will be used
: Be clear and honest
Create
button at the bottomUsers can create their personal Twitter token in two different ways. Each method is outlined below.
httpuv
package to be installed.## install httpuv if not already if (!requireNamespace("httpuv", quietly = TRUE)) { install.packages("httpuv") }
Keys and tokens
to retrieve your keys.Consumer API keys
(aka "API Secret").create_token()
.## load rtweet library(rtweet) ## store api keys (these are fake example values; replace with your own keys) api_key <- "afYS4vbIlPAj096E60c4W1fiK" api_secret_key <- "bI91kqnqFoNCrZFbsjAWHD4gJ91LQAhdCJXCj3yscfuULtNkuu" ## authenticate via web browser token <- create_token( app = "rstatsjournalismresearch", consumer_key = api_key, consumer_secret = api_secret_key)
api_key
match## view token (you should see the correct app name)
token
Keys and tokens
to retrieve your keys.Consumer API keys
(aka "API Secret").Access token & access token secret
and click Create
create_token()
.## store api keys (these are fake example values; replace with your own keys) api_key <- "afYS4vbIlPAj096E60c4W1fiK" api_secret_key <- "bI91kqnqFoNCrZFbsjAWHD4gJ91LQAhdCJXCj3yscfuULtNkuu" access_token <- "9551451262-wK2EmA942kxZYIwa5LMKZoQA4Xc2uyIiEwu2YXL" access_token_secret <- "9vpiSGKg1fIPQtxc5d5ESiFlZQpfbknEN1f1m2xe5byw7" ## authenticate via web browser token <- create_token( app = "rstatsjournalismresearch", consumer_key = api_key, consumer_secret = api_secret_key, access_token = access_token, access_secret = access_token_secret)
create_token()
function should automatically save your token as an environment variable for you. So next time you start an R session [on the same machine], rtweet should automatically find your token.api_key
match.## check to see if the token is loaded library(rtweet) get_token()
That's it!
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.