Tutorial 1. Azure Lab: Twitter and Tweepy

This lab will walk you through the process of using Azure tools to analyze Twitter. We’ll get OAuth Access Keys from Twitter first. We’ll use the access keys with Tweepy to make sure they work and to learn some fun things you can do on your own computer. Lastly, we use Azure’s Stream Analytics.

1.1 Getting OAuth Access Tokens

First, we’ll need to get tokens that allow our applications to access Twitter remotely. It isn’t too difficult because Twitter provides a decent guide here: https://dev.twitter.com/oauth/overview/application-owner-access-tokens

However, this guide is a little bit outdated and includes more information than we need so I’ll go over what we need.

First, you will need a twitter account. If you don’t have one, go ahead and make one on Twitter’s website.

a) Head to the Twitter Apps page.

The screen should look somewhat like this:

1

b) Click on “Create New App” (highlighted in green).

2

You should be brought to a screen with this on it:

Fill in the information. None of it is important to what we’ll be doing, you could even use the exact entries I showed and it would work.

c) Scroll down, click “Yes, I agree” then “Create your Twitter application”.

3

d) Click the “Key and Access Tokens” tab (highlighted in yellow)
e) Click “Create my Access Tokens” (highlighted in green)

Now you should be at a screen that looks like this:

4

Congratulations you have your OAuth Twitter keys! They are the ones labelled “Consumer Key”, “Consumer Secret”, “Access Token”, and “Access Token Secret”.

1.2 Using Tweepy for Local Twitter Analysis

Most people already have Python (the language for Tweepy) installed. In case you don’t, I’ll quickly go over how to set it up.

  1. Download Python 3.4.4 (the latest supported on Windows) from here: https://www.python.org/downloads/
  2. Check the option to add Python to your PATH when installing.
    • If you’re too good for automation you can add Python to your PATH by adjusting your environment variables and adding python’s PATH to your system variables list.
  3. Install Tweepy from here (the pip method is the easiest): https://github.com/tweepy/tweepy
  4. Download a Python IDE of your choice (I use PyCharm), or use the command line to run some example scripts. Here’s a guide: http://pythonprogramminglanguage.com/getting-started/

Awesome, now you should have some knowledge of making a Python script.

tweepy_code

Follow some of the guides on the Tweepy site or simply make a script like this:

Tweepy can do much more than just receive tweets, though. The only limit is your imagination. Let’s try some other activities with Tweepy:

  1. Send a tweet, @ one of your friends or a random person.
  2. Find how many followers Kanye West has.
  3. Print Scot Finnie’s (@ScotFinnie) last 100 tweets.

Give each of them a try, but if you need help the answers will be here.

tweepy_code_2

Answer (I)
Answer (II)
Answer (III)

tweepy_code_3

tweepy_code_4

Tweepy can be used for much more than this. We’re focusing on Azure, but feel free to try more things with Tweepy as well.

Continue in Tutorial 2 …

Tutorial 2 will walk you through setting up the stream analytics job using Twitter and Azure together.