33
Fun! with the Twitter API Stephanie Kim, @stephlkim Erin Shellman, @erinshellman June 30, 2014 Seattle PyLadies presents…

Fun! with the Twitter API

Embed Size (px)

DESCRIPTION

This was a fun workshop introducing the core functionality of the Twitter API, presented by myself and Stephanie Kim of Seattle PyLadies.

Citation preview

Page 1: Fun! with the Twitter API

Fun! with the Twitter API

Stephanie Kim, @stephlkim Erin Shellman, @erinshellman

!June 30, 2014

Seattle PyLadies presents…

Page 2: Fun! with the Twitter API
Page 3: Fun! with the Twitter API

Every other Monday. http://www.meetup.com/Seattle-PyLadies/

Page 4: Fun! with the Twitter API

Intro to Python http://www.meetup.com/Girl-Develop-It-Seattle/

Page 5: Fun! with the Twitter API

APIs describe how software communicates

• Application Programming Interfaces often come in the form of a module containing specialized classes.

Page 6: Fun! with the Twitter API
Page 7: Fun! with the Twitter API
Page 8: Fun! with the Twitter API

REST APIs interface consumers with resources on a server

• Representational state transfer (REST)

• REST APIs are specifications of remote calls exposed to API consumers.

1. Separate client from server.

2. Stateless.

3. Use HTTP/HTTPS.

Page 9: Fun! with the Twitter API

What could you build?

Page 10: Fun! with the Twitter API
Page 11: Fun! with the Twitter API

OAuth

OAuth is an open standard that allows us to access protected resources hosted by a resource server.

https://dev.twitter.com/docs/auth/authorizing-request

Page 12: Fun! with the Twitter API

Lets get some tokens! https://apps.twitter.com/

Page 13: Fun! with the Twitter API

Reading documentation is 90%https://dev.twitter.com/docs/api/1.1

Page 14: Fun! with the Twitter API

Request verbs• There are 5 common methods a client can apply to a

resource:

• GET

• HEAD

• POST

• PUT

• DELETE

Page 15: Fun! with the Twitter API

The anatomy of a request

• Request Line - Tells the server what type of request is being sent (e.g. GET, POST, PUT, DELETE)

• Header - Send over any required values, like security tokens.

• Body - What resource are you asking for?

Page 16: Fun! with the Twitter API

request line

header

body

Page 17: Fun! with the Twitter API

Responses

• A successful request to the server results in a response, hopefully containing the resource you requested.

• The response will contain a 3-digit status code starting with 1, 2, 3, 4, or 5.

Page 18: Fun! with the Twitter API

Response Codes

• 1__: Working on the request.

• 2__: Everything’”⁹s cool.

• 3__: Everything’”⁹s cool, but something else is happening.

• 4__: Oh man, not cool.

• 5__: The server errored out.

See: https://dev.twitter.com/docs/error-codes-responses

Page 19: Fun! with the Twitter API

The response also has a response line, header and body• Similarly to the request, a response contains a

response line, a header and a body.

Page 20: Fun! with the Twitter API

https://github.com/Seattle-PyLadies/TwitterApiWorkshop

Page 21: Fun! with the Twitter API
Page 22: Fun! with the Twitter API
Page 23: Fun! with the Twitter API
Page 24: Fun! with the Twitter API

https://dev.twitter.com/docs/api/1.1/get/statuses/retweets_of_me

Page 25: Fun! with the Twitter API
Page 26: Fun! with the Twitter API

https://dev.twitter.com/docs/api/1.1/post/statuses/update

Page 27: Fun! with the Twitter API
Page 28: Fun! with the Twitter API
Page 29: Fun! with the Twitter API
Page 30: Fun! with the Twitter API
Page 31: Fun! with the Twitter API

Make your own!

Page 32: Fun! with the Twitter API

Teaser for next time: http://it-stinks.herokuapp.com/

Page 33: Fun! with the Twitter API

Resources1. Programmable Web. http://

www.programmableweb.com/

2. Designing a RESTful API with Flask. http://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask

3. Cool mashups made possible with APIs. http://mashable.com/2009/10/08/top-mashups/

4. Great book about REST APIs. http://www.amazon.com/RESTful-Web-APIs-Leonard-Richardson-ebook/dp/B00F5BS966