0% found this document useful (0 votes)
8 views4 pages

Activity. Streaming Twitter Data

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Activity. Streaming Twitter Data

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Activity: Exploring streaming Twitter data

Learning Goals:

By the end of this activity, you will be able to:

1. View the text of Twitter data streaming in real-time containing specific words.
2. Create plots of the frequency of streaming Twitter data to see how popular a word is.

NOTE: You must complete a Twitter developer App account before you begin this activity.

--------

What is a Twitter developer App?


Accessing the Twitter APIs requires a set of credentials that you must pass with each request. These
credentials can come in different forms depending on the type of authentication that is required by
the specific endpoint that you are using. For example, user context requires an API key and secret
and a set of access tokens that are specific to the user that you are making the request on behalf of.

You will be generating these keys and tokens that you pass along with your API requests with a
Twitter developer App. Each Twitter App will be able to generate its own API key and API secret key
that you will use to make requests on behalf of the App, as well as access tokens and access token
secret that you will use to make requests on behalf of the owning user.

In addition to generating the keys and tokens necessary to make Twitter API requests, you will also
be able to set access permissions, document the use case or purpose for the App, and modify other
settings related to your App developer environment from within the management dashboard.

More information can be found here: https://developer.twitter.com/en/docs/apps/overview

---------

Instructions:
Step 1. Open a terminal shell and navigate to the json folder. Open a terminal shell as shown
below:

Run cd json if you are already in the labactiv folder, otherwise run cd
Downloads/labactiv/json
Step 2. Create your authentication file. Create an authentication file called auth, containing your API
key and secret, and your set of access tokens. For this you will have to have created a Twitter
developer account, as mentioned earlier.

Please name your authentication file auth, and include the required information in the following
order:
consumer_key
consumer_secret
access_token
access_token_secret

Your auth file should look like this:

Run ls to see the data files and scripts within the json folder:

Notice that the auth file must be copied in this folder, as it will be used by ./LiveTweets.py.

Step 3. View real-time tweets. We can view the contents of tweets in real-time by running the
LiveTweets.py script. Run LiveTweets.py president to see the tweets containing the word president:

./LiveTweets.py president

The output displays two columns: the first is the timestamp of the tweet, and the second is the text
of the tweet.
When you are done, enter Control-c to stop the script.

Let's run LiveTweets.py time to see the tweets containing the word time:
./LiveTweets.py time

You can also try your name or any other word you want.

Step 4. Plot real-time frequency of tweets. We can create a plot showing the frequency of tweets
containing a specific word. Run PlotTweets.py president to create the plot for the word
president:
./PlotTweets.py president
In this plot, we can see the variation over time of the number of tweets per second containing the
word president. Over this time period, the maximum was 58 tweets per second (13th second).

When you are done looking at the plot, click in the terminal window and press enter.

Now let's look at the frequency plot for the word time:
./PlotTweets.py time

In this plot, we can see the maximum number of tweets per second containing the word time was
about 67 (6th second) – higher than the maximum for the word president.

You might also like