Twitter developer account
Check here to learn how to apply for a twitter developper account.
After that you can apply here. Make sure you complete the form with serious and valid information only, because your application needs to be approved by Twitter and it can take up to 48 hours before you are approved.
Twitter App
In this section you will learn how to create a twitter app.
Visit the Twitter Developers Site
The first thing you need to do is head on down to https://developer.twitter.com/. In order to create an account, all you need to do is click on the “Sign In” link at the top right.
Sign in with your Twitter Account
Next, sign in with the Twitter account you want to associate with your app.
Go to “Apps”
Once you’re logged in, click on the downwards arrow to the right of your Twitter image and select “Apps”. This is where all your registered Twitter apps will appear.
Create a New Application
If you are new to the Developers site you won’t see any applications registered. Either way, it’s time to create our first application. To do this, click on the big “Create an app” button.
Access Tokens
You can read the rtweet
package vignette to learn how to obtain and use Twitter API access tokens for use in the rtweet
package.
Create Your Access Token
Click the "Create my access token" button. This takes a few seconds, so if you don’t see the access tokens on the next screen, you may have to refresh the page a few times.
Choose What Access Type You Need
Change application type to ‘Read & Write’ to give the application permission to follow other accounts on your behalf. This will require that you verify your mobile phone within your twitter account.
Make a Note of Your OAuth Settings
Once you’ve done this, make a note of your OAuth settings.
- Consumer Key
- Consumer Secret
- OAuth Access Token
- OAuth Access Token Secret
It goes without saying that you should keep these secret. If anyone was to get these keys, they could effectively access your Twitter account.
Collecting Twitter Data
Searching Tweets
Search for 1000 (non-retweeted) tweets containing the covid19 hashtag. Note: Be aware that you can search for up to 15000 (non-retweeted) tweets per 15 minutes.
# search for 1000 tweets using the covid19 hashtag
covid19 <- search_tweets("#covid19", n=1000, include_rts = FALSE, retryonratelimit = TRUE)
# preview tweets data
covid19
# preview users data
users_data(covid19)
The analysis called "A global pandemic on twitter" by Jason Timm is using the rtweet
package, check this here.
References
This course uses the rtweet
documentation.
Acknowledgments
To cite this course:
Warin, Thierry. 2020. “Covid-19 Simulation: A Data Science Perspective.” doi:10.6084/m9.figshare.12020994.v1.