Like A Girl

Pushing the conversation on gender equality.

Code Like A Girl

How to Visualize twitter hashtags: #blockchain

Prerequisites: Basic Programming knowledge and an appetite to learn some fun stuff.

By the end of this tutorial you will be able to: Collect data through twitter API, clean the tweets, extract hashtags and generate word cloud of top hashtags.

Twitter provides libraries spanning every language from Java to Ruby to Objective C. You can check this link to understand the usage for your favorite language.

In this tutorial, we will use R as it is widely used in Data Science analysis in real world.

Let’s begin

To use the twitter API, we have to get the consumer key, consumer secret and access token and access token secret.

What are they?

Consumer key is the API key, used by the application to identify the client(here the client is you).

Consumer secret is the client password to authenticate with the authentication server (like Twitter server).

Access token defines the privileges of the client (what she can access and what she cannot).

Access token secret is the password sent when the client wants to use the application’s (like Twitter’s) data.

To get them go to twitter’s application management page and sign in using your twitter account.

I have already created two applications in my session, so don’t be surprised when your page is empty.

Start by creating a new application for this project.

Click on Create New App button and fill the details. Give the name and description of your application and mention its URL. (If you don’t have a url, you can mention a placeholder i.e. A callback url is optional.

Submit the form.

You should see a new screen, with application settings, and an option to create access tokens.

To create your token click on ‘Create my access token’ button.

Woohoo!! You now have consumer keys and access keys of twitter API and hence you now have read and write permissions to your twitter account. This means, you can now use these keys to access Twitter database and get latest tweets , post tweets to your account from your code.

We will use these keys to retrieve tweets of the topic, “Blockchain”, and generate a cool word cloud from it.

We will be using Jupyter notebook and R language. You can follow our example in the below notebook.

Feel free to experiment with the code by changing the tweet topic and type of Word Clouds.

Happy Coding!