library(tweetbotornot2)
This vignette provides background and addresses commonissues related to obtaining access (authorization) to Twitter’s APIs. It also introduces two authorization methods–the default (user) authorization method and the application-only (bearer) authorization method–and explains some key differences between the two.
Use of {tweetbotornot} typically1 requires, at a minimum, (a) internet connection and (b) an active Twitter account. The latter is needed because Twitter requires authentication prior to use of their REST API. As a result, to use key functions of {tweetbotornot}, users must either approve the embedded {rtweet} rstats2twitter application (this allows {rtweet} to communicate from R to Twitter’s APIs) or provide their own application and account credentials. If a user is already signed into Twitter in their default web browser, this can be done with a single click. Otherwise, users must sign-in to Twitter and then click.
If you’re working in an interactive R session on a local machine (in the RStudio application, for example), this process should be relatively straight forward.1 However, if you’re working on a remote server or in the cloud (in RStudio Server, for example), then it’s a bit trickier. The easiest solution is to start a local, interactive session of R and then do the following:
On a machine with a local version of R, send API request via {rtweet}
rstats <- rtweet::search_tweets("rstats")
The above code actually creates (as a side effect) a Twitter token for you. So, on the same machine, save the token as an .rds
file
Upload the saved token file to your cloud/server
Once the token is uploaded to the cloud, you can read the token file and specify the resulting object in each {tweetbotornot} call, e.g.,
token <- readRDS("rtweet_token.rds")
predict_bot("jack", token = token)
or set the path to the saved token as an R environment variable. The latter option (example below) allows you to avoid having to specify the token each time.
Sys.setenv(TWITTER_PAT = "/path/to/rtweet_token.rds")
predict_bot("jack")
or set the R environment variable for current and future sessions (on a given machine), you can also try tfse::set_renv()
.
tfse::set_renv(TWITTER_PAT = "/path/to/rtweet_token.rds")