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, 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".
Users can create their personal access 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 Access Tokens
to retrieve your keys.
Keys and Access Tokens
tab, locate the values Consumer Key
(aka "API Key") and Consumer Secret
(aka "API Secret").
create_token()
.## autheticate via web browser token <- create_token( app = "rtweet_token", consumer_key = "XYznzPFOFZR2a39FwWKN1Jp41", consumer_secret = "CtkGEWmSevZqJuKl6HHrBxbCybxI1xGLqrD5ynPd9jG0SoHZbD")
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()
## check to see if the token is loaded identical(twitter_token, get_token())
Keys and Access Tokens
to retrieve your keys.
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 and Access Tokens
tab, scroll down to Token Actions
and click Create my access token
.
Access Token
and Access Token Secret
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.## authenticate via access token token <- create_token( app = "my_twitter_research_app", consumer_key = "XYznzPFOFZR2a39FwWKN1Jp41", consumer_secret = "CtkGEWmSevZqJuKl6HHrBxbCybxI1xGLqrD5ynPd9jG0SoHZbD", acess_token = "9551451262-wK2EmA942kxZYIwa5LMKZoQA4Xc2uyIiEwu2YXL", access_secret = "9vpiSGKg1fIPQtxc5d5ESiFlZQpfbknEN1f1m2xe5byw7")
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()
## check to see if the token is loaded identical(twitter_token, get_token())
That's it!
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.