Azure Tweet Sentiment Analysis: End To End Solution – Part 2 (The Twitter Account, App & and Event Hub)

Before we do anything we need a Twitter account. Get that sorted.

Next, we need to go to the Twitter Application Management Site this is where we will register an app that will enable us to retrieve a couple of keys which we’ll need to paste into our app that will open up a stream of tweets and send them off to our event hub.

The App registration needs a couple of fields populated. Enter something that makes sense to you, tick the box to say you understand the T&C’s (if you do, of course) and create your app.


On creation you will will be taken to the key and access tokens tab. Jot down the following keys and secrets. As we’ll be using these in a minute within our app.

  • Consumer Key
  • Consumer Secret
  • Access Token
  • Access Token Secret


Create The Event Hub

  1. Go to the Azure Portal and click on ‘Create A Resource’.
  2. Enter Event hub once the resource is selected, click create.
  3. Create your namespace with the values that you want.


We’ll be needing one more thing here and that is the SAS key so we have the rights to send our tweets to it. Simply click on the ‘Shared Access Policies’ blade, click on the RootManageSharedAccessKey and copy down the connection string-primary key.


Now we have the namespace, we’ll need the actual event hub. Click on the plus sign with Event Hub written next to it.


After that .The capture section is asking you if you want a storage account to be associated to the event hub so you can capture what is being ingested. In our case, we won’t be needing it.


And there we have it for the Event hub. Now on to writing a bit of code.

Making the App

We’ll be using C#, but there is nothing stopping you from using your favourite language.

First create a console app.


Then go to NuGetPackageManager and download the TweetInviApi, install it and associate it with your project.


And do the same with WindowsAzure.ServiceBus


Now we can do a bit of coding.

Reference the TweetinviAPI and EventHub libraries we downloaded

using System;
using Microsoft.Azure.EventHubs;
using System.Text;
using Tweetinvi;

Now get connection string-primary key we retrieved from when we created the event hub namespace and after the final semicolon, add the following EntityPath=<YOUREVENTHUBNAME>. In my case, it was EntityPath=tweethub. The whole sting should be made up of the following.

<COPIED connection string-primary key>;EntityPath=<YOUR EVENT HUB NAME”;






Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s