Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. from apiclient import discovery
  2. from oauth2client import appengine
  3. from oauth2client import client
  4. from google.appengine.api import memcache
  5. from oauth2client import client
  6.  
  7. CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secrets.json')
  8. http = httplib2.Http(memcache)
  9. service = discovery.build("urlshortener", "v1", http=http)
  10. decorator = appengine.oauth2decorator_from_clientsecrets(
  11. CLIENT_SECRETS,
  12. scope='https://www.googleapis.com/auth/plus.me',
  13. message=MISSING_CLIENT_SECRETS_MESSAGE)
  14.  
  15.  
  16. class TestHandler(basehandler.BaseHandler):
  17.  
  18. @decorator.oauth_required
  19. def get(self):
  20. param=self.request.get('c')
  21. # post_url = param
  22. longurl = 'http://myapp.appspot.com/simple/?c=B62K4QBRR2DLRAGYN2GWPTGG6D425DMNEPFKDUARROCNI7QIGTCXGYHPEVL6GENQDBJDSYVINWJHI3267KIODPUKE7I4Y6KMML64WCCPPBRP6E7E4G7JL6IHOKF7N3N56L7V3XFGQJIJOF3VJ5MM6V4QD5CYF7GVN3JHB2FXR3EMRXOXDO4Z5WMTB6Y3WLLM5H7674ELU37KC==='
  23. scope='https://www.googleapis.com/auth/urlshortener')
  24.  
  25. try:
  26. url = service.url()
  27.  
  28. # Create a shortened URL by inserting the URL into the url collection.
  29. body = {'longUrl': longurl}
  30. resp = url.insert(body=body).execute()
  31. pprint.pprint(resp)
  32.  
  33. short_url = resp['id']
  34.  
  35. strin = short_url
  36. return self.response.write("<html><body><p>"+str(strin)+"</p></body></html>")
  37. except client.AccessTokenRefreshError:
  38. print ('The credentials have been revoked or expired, please re-run'
  39. 'the application to re-authorize')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement