Difference between revisions of "C4LN 2012: Intro to the Twitter API"

From Code4Lib
Jump to: navigation, search
(working up a terse OAuth intro)
(+more OAuth and setup details)
Line 61: Line 61:
 
* user (resource owner) -- ''user''
 
* user (resource owner) -- ''user''
  
 +
Credentials
 +
* consumer credentials (consumer key & consumer secret)
 +
* access credentials (access token & access secret)
 +
* (also request token & secret)
  
* receive OAuth keys
+
OAuth workflow:
** '''<tt>consumer_key</tt>'''
+
* user goes to server and says they'd like to authorize application ''X'' to do action ''Y''
** '''<tt>consumer_secret</tt>'''
+
* server generates access token which represents the combination of the specific app & the specific user & the specific level of access the user has granted to that app
 +
* user feeds the access token to the app
 +
* the app can then present the access token to the server (in combination with its consumer credentials) and be permitted to do whatever's been authorized
  
  
 
=== Setup ===
 
=== Setup ===
  
 +
* after you've set up your app, you receive your OAuth consumer keys:
 +
** '''<tt>consumer_key</tt>'''
 +
** '''<tt>consumer_secret</tt>'''
 +
 +
The first thing you're going to want to do is go into your app settings and set the correct level of access that your app is going to request from users.  This is under the '''Settings''' tab:
  
* tabs we're initially interested in: Details & Settings
+
* Application type:
* Settings tab:
+
** Read
** Application type:
+
** Read/Write
*** Read
+
** Read/Write/Access DMs
*** Read/Write
+
*** Read/Write/Access DMs
+
  
 +
You are probably going to want one of the latter two.  Which one depends on whether or not your app is going to work with DMs (direct messages) or not.
  
 +
You can also fill in the rest of the self-explanatory fields in the Details and Settings tabs as you like (organization, etc).
  
 
== Bot-specific stuff ==
 
== Bot-specific stuff ==

Revision as of 14:16, 24 May 2012

Presenter: Rick Scott - @shadowspar

API Overview


Parts

  • the REST API
  • the Streaming API
  • the Search API


REST API

  • query→response based access
  • the mainstay of the API; the first part of it you'll want to be concerned with, and the part you'll likely use most

Streaming API

  • aka drinking from the firehose =)
  • persistent connection
  • push-based communication w/ v.high ratelimit (1% of all tweets)

Search API

  • just like it says on the tin
  • also trending topics


Find your library

https://dev.twitter.com/docs/twitter-libraries has a good list


Creating a new app

First steps

Huzzah! You have your very own app!

A brief segue into OAuth

http://hueniverse.com/oauth/guide/intro/

OAuth metaphor: valet key to your car

  • lets an app act on behalf of a user when dealing with some service
  • lets a user give an app specific permissions to interact with a service on their behalf

Roles in OAuth:

  • consumer (client) -- your app
  • service provider (server) -- Twitter
  • user (resource owner) -- user

Credentials

  • consumer credentials (consumer key & consumer secret)
  • access credentials (access token & access secret)
  • (also request token & secret)

OAuth workflow:

  • user goes to server and says they'd like to authorize application X to do action Y
  • server generates access token which represents the combination of the specific app & the specific user & the specific level of access the user has granted to that app
  • user feeds the access token to the app
  • the app can then present the access token to the server (in combination with its consumer credentials) and be permitted to do whatever's been authorized


Setup

  • after you've set up your app, you receive your OAuth consumer keys:
    • consumer_key
    • consumer_secret

The first thing you're going to want to do is go into your app settings and set the correct level of access that your app is going to request from users. This is under the Settings tab:

  • Application type:
    • Read
    • Read/Write
    • Read/Write/Access DMs

You are probably going to want one of the latter two. Which one depends on whether or not your app is going to work with DMs (direct messages) or not.

You can also fill in the rest of the self-explanatory fields in the Details and Settings tabs as you like (organization, etc).

Bot-specific stuff

  • create an account for your bot
  • authorize it on your app


Rules of Conduct

General Rules of the Road and TOS

Rate limits

Other gotchas

  • Repeated tweets


Example

http://twitter.com/inetkami https://github.com/rickscott/inetkami

Other Miscellany

  • t, a Ruby command-line interface to the Twitter API