Permalink
Browse files

Merge pull request #45 from brunoqc/master

Ported the github example to google
  • Loading branch information...
2 parents 59ad968 + 46a8b24 commit f046d504f5533f3d59be42673c82fabf6acd1244 @maxcountryman maxcountryman committed Oct 1, 2012
Showing with 32 additions and 0 deletions.
  1. +32 −0 examples/google.py
View
@@ -0,0 +1,32 @@
+from rauth.service import OAuth2Service
+
+# Get a real consumer key & secret from:
+# https://code.google.com/apis/console/
+google = OAuth2Service(
+ name='google',
+ authorize_url='https://accounts.google.com/o/oauth2/auth',
+ access_token_url='https://accounts.google.com/o/oauth2/token',
+ consumer_key='',
+ consumer_secret='')
+
+redirect_uri = 'https://github.com/litl/rauth/'
+
+print 'Visit this URL in your browser: ' + google.get_authorize_url(redirect_uri=redirect_uri, scope='profile email')
+
+# This is a bit cumbersome, but you need to copy the code=something (just the
+# `something` part) out of the URL that's redirected to AFTER you login and
+# authorize the demo application
+code = raw_input('Enter code parameter (code=something) from URL: ')
+
+# create a dictionary for the data we'll post on the get_access_token request
+data = dict(code=code, grant_type='authorization_code', redirect_uri=redirect_uri)
+
+# retrieve the access token
+access_token = \
+ google.get_access_token('POST', data=data).content['access_token']
+
+# make a request using the access token
+user = google.get('https://www.googleapis.com/oauth2/v1/userinfo',
+ params=dict(access_token=access_token)).content
+
+print 'currently logged in as: ' + user['email']

0 comments on commit f046d50

Please sign in to comment.