From 820d423ce85634e01bb6e8af467ce7ab0fda05d8 Mon Sep 17 00:00:00 2001 From: Josh Roesslein Date: Sat, 8 Aug 2009 14:42:26 -0500 Subject: [PATCH] Added tutorial 2 and introduction. --- tutorial/t0.py | 14 +++++++++ tutorial/{1.py => t1.py} | 0 tutorial/t2.py | 62 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 tutorial/t0.py rename tutorial/{1.py => t1.py} (100%) create mode 100644 tutorial/t2.py diff --git a/tutorial/t0.py b/tutorial/t0.py new file mode 100644 index 0000000..3735d1c --- /dev/null +++ b/tutorial/t0.py @@ -0,0 +1,14 @@ +""" Introduction + +This series of tutorials is designed to introduce you to key +concepts of Tweepy. By the end of this series you should be ready +to create your grand Twitter application with Tweepy! + +If you get lost on your journey to becoming a Tweepy guru, feel +free to post questions to tweepy@googlegroups.com + +Each tutorial file is named tX.py where X is the tutorial number. +Work your way from 1 and up. + +Author: Joshua Roesslein +""" diff --git a/tutorial/1.py b/tutorial/t1.py similarity index 100% rename from tutorial/1.py rename to tutorial/t1.py diff --git a/tutorial/t2.py b/tutorial/t2.py new file mode 100644 index 0000000..75d85a9 --- /dev/null +++ b/tutorial/t2.py @@ -0,0 +1,62 @@ +import tweepy +from t1 import * + +""" Tutorial 2 -- API + +This tutorial will focus on creating and using the API class. +The API class is the primary interface between your application +and Twitter's API. It implements most of the endpoint documented here: + http://apiwiki.twitter.com/Twitter-API-Documentation +""" + +""" +The API class can be used in either authenticated or non-authenticated modes. +First let's demonstrate using the API class without authentication... +""" +no_auth_api = tweepy.API() + +""" +Let's query the public timeline and print it to the console... +""" +public_timeline = no_auth_api.public_timeline() +print 'Public timeline...' +for status in public_timeline: + print status.text + print 'from: %s' % status.user.screen_name + +""" +Tweepy provides a non-authenticated instance of the API for you already +so you don't normally need to create one your self. +""" +tweepy.api # non-auth instance of API + +""" +Any endpoint that does not require authentication can be accessed +with this non-authenticated API instance. If you try to access an +API endpoint that does require authentication, a TweepError exception +will be raised. +""" + +""" +Now we will create an authenticated instance of the API class +using the auth handler we created in tutorial 1. +""" +auth_api = tweepy.API(oauth_auth) + +""" +Let's query the authenticated user's friends timeline +and print it to the console... +""" +friends_timeline = auth_api.friends_timeline() +for status in friends_timeline: + print status.text + print 'from: %s' % status.user.screen_name + +""" The End + +So that wraps up this tutorial. You now know how to create both +non-authenticated and authenticated instances of the API class. + +Onto the next tutorial! +""" + -- 2.25.1