Generate a consumer key - save the consumer key and consumer secret
Generate the access token and secret
Learn more at the Credera Blog
Credera is a management and technology consulting company. Their blog has a number of helpful posts covering business and technology insights. My code presented here follows their instructions from a 3-part series on extracting data from Twitter from their technology insights blog.
See all their posts on Twitter applications at Credera
You will need to install the following packages in R: twitteR and ROAuth for “talking” to Twitter. You also need the tm and wordcloud packages to parse the tweets and then create the wordcloud figure. More information on R packages is available at Quick-R and CRAN
Get your authenticated credentials (CAcert and cURL)
For Windows users you need to get the cacert.pem file. This gets stored in your local directory so be sure that your working directory is set how you want it. Run getwd() to check what R thinks is your current working directory. Use setwd(c:/xxxx/xxxx) to set the path to what you want.
IMPORTANT NOTE
At my Twitter developer site I had to update the permissions for the app to read, write and direct messages instead of just read permissions which was my default. See your application settings at something like https://apps.twitter.com/app/xxxxxxx for your specific Twitter developer account to update your settings. When I only had read permissions I kept getting “Authorization Required” error like below …
Now that you have your Twitter application configured for read, write and direct messages permissions, download the CAcert.
Next create an object with the authentication details for later sessions. You will need your consumer Key and Secret from your Twitter app to input here.
Next do a search on twitter and parse through the tweets and create a wordcloud
This may take a few minutes to run depending on the amount of tweets being extracted.
Here are some of the tweets extracted using head(tweets) to pull the first few tweets extracted.
The next set of commands will parse through these tweets and extract the key words we will use in the final wordcloud.
Here is what the cleaned up text now looks like for the 1st tweet extracted above.
Finally, generate the wordcloud for all of the extracted content from these 1499 tweets.