Automate Twitter Sentiment Analysis using Zapier and Watson (no coding required)

Pavan Tummala
7 min readJan 6, 2019

Twitter is a great source of data for analyzing real-time trends related to a topic of your interest. You can collect tweets that mention a certain brand, event or a person and start to see a pattern emerge. You can perform Sentiment analysis on tweets to determine if a certain brand or event is trending positive or negative in the social network.

This step by step tutorial will show how to collect tweets related to a topic of your interest, determine the sentiment of the text in the tweet, and store the results in a Google spreadsheet for further analysis.

Once we have everything set up your spreadsheet will look like this.

If you do not have any programming background, don’t worry. There is no coding involved and we will use the excellent workflow automation service from Zapier to tie all the things together. Let’s get started!

1. What you need for this tutorial

If you don’t have an active account for the following services, go ahead and signup. All these services are available for free, with additional capabilities available in paid versions.

  1. Twitter
  2. Zapier
  3. Google Sheets
  4. IBM Cloud

We will use Watson Natural Language Understanding (NLU) for analyzing the tweet Sentiment. If you are not familiar with NLU, you can read an overview here.

Follow these steps to get an API key for NLU.

Log in to IBM Cloud and go to the dashboard. Click on Create resource button on top-right.

In the Catalog page that opens, click on AI in the left navigation and select Natural Language Understanding tile.

Pick a region where you want your NLU instance to be created. For best performance pick a region in your country. But for this tutorial, any region will do fine. Scroll down, select the Lite plan and click on the Create button.

After the page loads, click on Manage in the left navigation. Note the API Key and the URL. We will be using them in subsequent steps.

What’s a Zap?

Log in to Zapier and click on the bright orange Make a Zap button (you won’t miss it). Zaps are workflows that connect apps together and are comprised of three components.

A Trigger that starts the Zap. For e.g. receiving an email in an inbox.

One or more Actions that you would like to perform once the trigger executes. For e.g. Add a certain label to the received email.

Tasks that are automatically executed as part of the Actions. Tasks are where Zapier’s magical automation happens. One Action can result in multiple tasks being executed. In the free account of Zapier, you are allowed 1000 tasks per month and five zaps.

For this tutorial, we will create a Zap with the following structure.

Configure a Trigger with a Twitter account and a search parameter

The Zap runs the Trigger every five minutes and pulls the latest tweets matching the search parameter.

Configure two Actions. The first Action will be a “Webhooks” action which will make an API call to NLU — sending the text of the tweet and requesting its sentiment. The second Action will insert the text of the tweet and the sentiment returned by NLU as a new row in a Google spreadsheet.

Trigger

Start by giving a name to the Zap, such as “TweetSentiment”. To start creating the Trigger, use the search bar on the right-hand side to look up Twitter.

After clicking on Twitter in the dropdown, you will see a screen to pick search criteria for tweets. Go ahead and select Search Mention and click Save+Continue. Next, you will be asked to provide your twitter account to be used for this Zap.

Once you complete the Twitter account authorization step, on the next screen you can configure the search term. I used the hashtag #CES2019 for checking the overall sentiment of the upcoming Consumer Electronics Show event. But feel free to experiment with your own search term here.

The following screen will show a sample result set of tweets based on your search criteria. Select one of the options and click Continue.

Action 1 — API call to Watson NLU

Let’s create our first Action. Select Action/Search in Add A Step section. Use the search bar on the right-hand side to lookup and select Webhooks by Zapier. Select GET as the request type and click on Continue. You will see a detailed form to configure the API request we are going to make to Watson NLU.

In the URL field, enter the URL to the NLU instance from the earlier step. It should look like this: https://gateway-wdc.watsonplatform.net/natural-language-understanding/api/

To request Sentiment, we are going to append the following parameters to the URL.

v1/analyze?version=2018–11–16&features=sentiment

So your full URL would look like this:

https://gateway-wdc.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2018-11-07&features=sentiment

In the Query String Params section, enter “text” in the first textbox and click on the small plus icon in the row. It will bring up all the attributes of a tweet you can use in this Action.

Select “Text” from the dropdown — which will be the text of the tweet.

Scroll to the Basic Auth section, and paste your NLU API key in this format:

apikey|your 44-digit apikey here.

In the last section named Headers, addContent-Type” as the key (first textbox), and “application/json” as the value.

Click on Continue and then Send Test to Webhooks by Zapier button. This will test if we have configured the Action properly and if everything checks out you should see Add a Step or Finish buttons. Click on Add a Step to proceed with the creation of our second Action.

Action 2 — Store results in Google spreadsheet

Lookup and select Google Sheets in the search bar. Select Create Spreadsheet Row and click on Save + Continue. You will be asked to connect your Google account in the next step.

In the next step, you will be asked to provide a Google Spreadsheet document and a worksheet within the document. To do that, go to Google Sheets and create a spreadsheet document. Create three columns in the document — Tweet Text, Sentiment, Sentiment Score. Give the document a name and come back to Zap configuration screen. In the Spreadsheet dropdown, select the document you have just created. If you don’t see the document, click on Refresh Fields button at the bottom. Select the worksheet within the document, most likely Sheet1.

Once you do that, you should see three additional fields below.

Click on the plus icon next to Tweet Text drop-down, select Search Mention and pick Text.

For the Sentiment dropdown, select GET and Sentiment Document Label. In the last field, Sentiment Score, select GET and Sentiment Document Score. Click on Continue and Send Test to Google Sheets in the following screen.

If all goes well, you will see a test was successful message. Click on the Finish button.

Turn on the Zap

Our Zap is now ready to be turned on. Toggle the OFF button to enable the Zap. In the free plan, the Zap will run every five minutes, finding matching tweets and storing its text and NLU sentiment in Google spreadsheet. Check your spreadsheet and you should start seeing data coming in if there are tweets matching the search parameter.

That’s it! Now that data is flowing in, you can create a live chart using the Sentiment Score column or calculate the average sentiment of the event per day.

I hope you found this tutorial useful. Feel free to ask a question or leave a comment. Thanks for reading and have a great year 2019!

--

--