Skip to Content
21 Recipes for Mining Twitter
book

21 Recipes for Mining Twitter

by Matthew A. Russell
January 2011
Beginner to intermediate
76 pages
1h 42m
English
O'Reilly Media, Inc.
Content preview from 21 Recipes for Mining Twitter

Chapter 1. The Recipes

Using OAuth to Access Twitter APIs

Problem

You want to access your own data or another user’s data for analysis.

Solution

Take advantage of Twitter’s OAuth implementation to gain full access to Twitter’s entire API.

Discussion

Twitter currently implements OAuth 1.0a, an authorization mechanism expressly designed to allow users to grant third parties access to their data without having to do the unthinkable—doling out their username and password. Various third-party Python packages such as twitter (easy_install twitter) provide easy-to-use abstractions for performing the “OAuth dance,” so that you can easily implement client programs to walk the user through this process. In the case of Twitter, the first step involved is registering your application with Twitter at http://dev.twitter.com/apps where Twitter provides you with a consumer key and consumer secret that uniquely identify your application. You provide these values to Twitter when requesting access to a user’s data, and Twitter prompts the user with information about the nature of your request. Assuming the user approves your application, Twitter then provides the user with a PIN code for the user to give back to you. Using your consumer key, consumer secret, and this PIN code, you retrieve back an access token and access token secret that ultimately are used to get you the authorization required to access the user’s data.

Example 1-1 illustrates how to use the consumer key and consumer secret to do the OAuth ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Mining the Social Web - Twitter

Mining the Social Web - Twitter

Mikhail Klassen
R: Mining Spatial, Text, Web, and Social Media Data

R: Mining Spatial, Text, Web, and Social Media Data

Bater Makhabel, Pradeepta Mishra, Nathan Danneman, Richard Heimann
The Hidden Cost of AI-Assisted Creativity

The Hidden Cost of AI-Assisted Creativity

Léonard Boussioux, Anil Doshi, Oliver Hauser, Kartik Hosanagar

Publisher Resources

ISBN: 9781449303624Errata Page