In this chapter we get you set up and running with the twinetverse, namely installing the packages and setting up rtweet to fetch tweets.
Then install the twinetverse with:
In the book we don’t explicitly load the package and assume you have it loaded in your environment (snippet below).
4.2 Setup rtweet
The rtweet package requires some set up. This is not only extremely easy but also very well explained on rtweet’s official website, so head over there if the short description below does not satisfy.
In essence, you will need a Twitter “app” to access its API, to create one:
- Head over to apps.twitter.com and login or signup if you do not have a Twitter account.
- Click create an app.
- In the following form, enter an app name, whatever you want, this does not matter.
- Enter a description, then again, it doesn’t matter.
- Under website, simply put a valid website, you can link to your Twitter profile if you do not have one, i.e.: https://twitter.com/jdatap
- Callback URL, this is important, in there put the following:
http://127.0.0.1:1410, exactly as is.
You’re now setup with an app, take note of the crendentials of your app under “Keys and Access Tokens”, as you will need it to create your token and fetch tweets:
- Consumer Key (
- Consumer Secret (
- Access Token (
- Access Token Secret (
Do NOT share those credentials or your token with anyone.
Create your token with like so.
library(twinetverse) TK <- create_token( "My Application Name", consumer_key = "XxxxXxXXxXx", consumer_secret = "XxxxXxXXxXx", access_token = "XxxxXxXXxXx", access_secret = "XxxxXxXXxXx" )
Ideally, also save it. There is no need to re-create a token everytime you want to download data. Once saved you can easily load it
readRDS (we’ll demonstrate that in the next chapter).
saveRDS(TK, file = "token.rds")
You’re now all set to build Twitter networks!
Wickham, Hadley, Jim Hester, and Winston Chang. 2018. Devtools: Tools to Make Developing R Packages Easier. https://CRAN.R-project.org/package=devtools.
Csárdi, Gábor, Hadley Wickham, Winston Chang, Jim Hester, Martin Morgan, and Dan Tenenbaum. 2018. Remotes: R Package Installation from Remote Repositories, Including ’Github’. https://CRAN.R-project.org/package=remotes.