2323import os
2424import pickle
2525
26- from apiclient .discovery import build
2726from oauth2client .appengine import CredentialsProperty
2827from oauth2client .appengine import StorageByKeyName
2928from oauth2client .client import OAuth2WebServerFlow
3635from google .appengine .ext .webapp .util import login_required
3736
3837
38+ FLOW = OAuth2WebServerFlow (
39+ client_id = '2ad565600216d25d9cde' ,
40+ client_secret = '03b56df2949a520be6049ff98b89813f17b467dc' ,
41+ scope = 'read' ,
42+ user_agent = 'oauth2client-sample/1.0' ,
43+ auth_uri = 'https://api.dailymotion.com/oauth/authorize' ,
44+ token_uri = 'https://api.dailymotion.com/oauth/token'
45+ )
46+
47+
3948class Credentials (db .Model ):
4049 credentials = CredentialsProperty ()
4150
@@ -49,37 +58,23 @@ def get(self):
4958 Credentials , user .user_id (), 'credentials' ).get ()
5059
5160 if credentials is None or credentials .invalid == True :
52- flow = OAuth2WebServerFlow (
53- client_id = '2ad565600216d25d9cde' ,
54- client_secret = '03b56df2949a520be6049ff98b89813f17b467dc' ,
55- scope = 'read' ,
56- user_agent = 'oauth2client-sample/1.0' ,
57- auth_uri = 'https://api.dailymotion.com/oauth/authorize' ,
58- token_uri = 'https://api.dailymotion.com/oauth/token'
59- )
60-
6161 callback = self .request .relative_url ('/auth_return' )
62- authorize_url = flow .step1_get_authorize_url (callback )
63- memcache .set (user .user_id (), pickle .dumps (flow ))
62+ authorize_url = FLOW .step1_get_authorize_url (callback )
63+ memcache .set (user .user_id (), pickle .dumps (FLOW ))
6464 self .redirect (authorize_url )
6565 else :
6666 http = httplib2 .Http ()
67-
68- resp , content1 = http .request ('https://api.dailymotion.com/me?access_token=%s' %
69- credentials .access_token )
70-
7167 http = credentials .authorize (http )
72- resp , content2 = http .request ('https://api.dailymotion.com/me' )
68+
69+ resp , content = http .request ('https://api.dailymotion.com/me' )
7370
7471 path = os .path .join (os .path .dirname (__file__ ), 'welcome.html' )
7572 logout = users .create_logout_url ('/' )
76- self .response .out .write (
77- template .render (
78- path , {
79- 'content1' : content1 ,
80- 'content2' : content2 ,
81- 'logout' : logout
82- }))
73+ variables = {
74+ 'content' : content ,
75+ 'logout' : logout
76+ }
77+ self .response .out .write (template .render (path , variables ))
8378
8479
8580class OAuthHandler (webapp .RequestHandler ):
0 commit comments