Note you are introducing 2 new packages lower in this lesson: igraph and ggraph.
# load twitter library - the rtweet library is recommended now over twitteR
library(rtweet)
# plotting and pipes - tidyverse!
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
# text mining library
library(tidytext)
# plotting packages
library(igraph)
##
## Attaching package: 'igraph'
## The following objects are masked from 'package:dplyr':
##
## as_data_frame, groups, union
## The following objects are masked from 'package:stats':
##
## decompose, spectrum
## The following object is masked from 'package:base':
##
## union
library(ggraph)
In order to download tweets, you will need a twitter account.
Then you will need a developer account. Follow this CRAN tutorial in order to create a developer account: https://cran.r-project.org/web/packages/rtweet/vignettes/auth.html
As an example, my developer account is: MC data mining. You basically need to provide twitter with a reason that you would like this account, and obviously, it is to learn to mine tweets for your data science class. It is typically a fast approval process.
Once you have created a developer app, you are ready to start.
Copy and paste the four keys (along with the name of your app) into an R script file and pass them along to create_token().
api_key <- “…” api_secret_key <- “…” access_token <- “…” access_token_secret <- “…”
#api_key <- "..."
#api_secret_key <- "..."
#access_token <- "..."
#access_token_secret <- "..."
api_key <- "onsqqdn6FkeFG2jeFLeODn6UE"
api_secret_key <- "50AZmbOZizq29Hiiy5a3kheDl93Z3ym5lWTxZLywLLGuswvX3b"
access_token <- "432673917-rOQ8W1Wgi1qAH1NeS3BbNByogRlrhq34kzqWgTrd"
access_token_secret <- "OgGb43o5Rwv5nGQvuocbHmkLVH7imPQsIUfzBjxQpxVoK"
## authenticate via web browser
token <- create_token(
app = "MC data minig",
consumer_key = api_key,
consumer_secret = api_secret_key,
access_token = access_token,
access_secret = access_token_secret)