Permalink
Browse files

reworking Service and Session concepts

  • Loading branch information...
maxcountryman committed Mar 3, 2013
1 parent 36cc56b commit c6447ddb5427246d58e6c2077bdc71404b4d1def
View
@@ -26,9 +26,9 @@
webbrowser.open(authorize_url);
url_with_code = raw_input('Copy URL from your browser\'s address bar: ')
-facebook.access_token = re.search('\#access_token=([^&]*)',
- url_with_code).group(1)
+access_token = re.search('\#access_token=([^&]*)', url_with_code).group(1)
+session = facebook.get_session(access_token)
-user = facebook.get('me').json()
+user = session.get('me').json()
print 'currently logged in as: ' + user['link']
@@ -38,6 +38,7 @@
client_secret=app.config['FB_CLIENT_SECRET'],
base_url=graph_url)
+
# models
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
@@ -84,10 +85,11 @@ def authorized():
# make a request for the access token credentials using code
redirect_uri = url_for('authorized', _external=True)
data = dict(code=request.args['code'], redirect_uri=redirect_uri)
- facebook.get_access_token(data=data)
+
+ session = facebook.get_auth_session(data=data)
# the "me" response
- me = facebook.get('me').json()
+ me = session.get('me').json()
User.get_or_create(me['username'], me['id'])
@@ -96,4 +98,5 @@ def authorized():
if __name__ == '__main__':
+ db.create_all()
app.run()
View
@@ -20,10 +20,10 @@
# create a dictionary for the data we'll post on the get_access_token request
data = dict(code=code, redirect_uri='https://github.com/litl/rauth/')
-# retrieve the access token
-github.get_access_token('POST', data=data)
+# retrieve the authenticated session
+session = github.get_auth_session(data=data)
-# make a request using the access token
-user = github.get('user').json()
+# make a request using the authenticated session
+user = session.get('user').json()
print 'currently logged in as: ' + user['login']
@@ -16,20 +16,16 @@
print 'Visit this URL in your browser: ' + authorize_url
pin = raw_input('Enter PIN from browser: ')
-access_token, access_token_secret = \
- linkedin.get_access_token(request_token,
- request_token_secret,
- method='POST',
- data={'oauth_verifier': pin},
- header_auth=True)
-
-response = linkedin.get('people/~/network/updates',
- params={'type': 'SHAR', 'format': 'json'},
- access_token=access_token,
- access_token_secret=access_token_secret,
- header_auth=True)
-
-updates = response.json()
+session = linkedin.get_auth_session(request_token,
+ request_token_secret,
+ data={'oauth_verifier': pin},
+ header_auth=True)
+
+r = session.get('people/~/network/updates',
+ params={'type': 'SHAR', 'format': 'json'},
+ header_auth=True)
+
+updates = r.json()
for i, update in enumerate(updates['values'], 1):
if 'currentShare' not in update['updateContent']['person']:
@@ -17,19 +17,15 @@
print 'Visit this URL in your browser: ' + authorize_url
pin = raw_input('Enter PIN from browser: ')
-access_token, access_token_secret = \
- twitter.get_access_token(method='POST',
- request_token=request_token,
- request_token_secret=request_token_secret,
- data={'oauth_verifier': pin})
+session = twitter.get_auth_session(request_token,
+ request_token_secret,
+ method='POST',
+ data={'oauth_verifier': pin})
params = {'include_rts': 1, # Include retweets
'count': 10} # 10 tweets
-r = twitter.get('statuses/home_timeline.json',
- params=params,
- access_token=access_token,
- access_token_secret=access_token_secret)
+r = session.get('statuses/home_timeline.json', params=params)
for i, tweet in enumerate(r.json(), 1):
handle = tweet['user']['screen_name'].encode('utf-8')
Oops, something went wrong.

0 comments on commit c6447dd

Please sign in to comment.