From 37129ca9f20bf21acf97900eca30ee245c03dbde Mon Sep 17 00:00:00 2001 From: Josh Roesslein Date: Mon, 10 Aug 2009 12:58:49 -0500 Subject: [PATCH] Update tutorial 1 to demo storing/loading oauth token via pickle. --- tutorial/t1.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tutorial/t1.py b/tutorial/t1.py index 951c777..81cf085 100644 --- a/tutorial/t1.py +++ b/tutorial/t1.py @@ -1,4 +1,5 @@ from getpass import getpass +import cPickle as pickle import tweepy """ Tutorial 1 -- Authentication @@ -51,14 +52,24 @@ oauth_auth.get_access_token(verifier) Okay we are all set then with OAuth. If you want to store the access token for later use, here's how... """ -access_token_store = oauth_auth.access_token -print 'Access token: %s' % access_token_store +access_token = oauth_auth.access_token +print 'Access token: %s' % access_token """ -And to re-create the OAuthHandler with that access token later on... +For later use we will keep the token pickled into a file. """ +token_file = open('oauth_token', 'wb') +pickle.dump(access_token, token_file) +token_file.close() + +""" +And to reload the token... +""" +token_file = open('oauth_token', 'rb') +oauth_token = pickle.load(token_file) +token_file.close() oauth_auth = tweepy.OAuthHandler(consumer_key, consumer_secret) -oauth_auth.access_token = access_token_store +oauth_auth.access_token = access_token """ Now let's plugin our newly created auth handler into an API instance -- 2.25.1