Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from apiclient import discovery
- from oauth2client import appengine
- from oauth2client import client
- from google.appengine.api import memcache
- from oauth2client import client
- CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secrets.json')
- http = httplib2.Http(memcache)
- service = discovery.build("urlshortener", "v1", http=http)
- decorator = appengine.oauth2decorator_from_clientsecrets(
- CLIENT_SECRETS,
- scope='https://www.googleapis.com/auth/plus.me',
- message=MISSING_CLIENT_SECRETS_MESSAGE)
- class TestHandler(basehandler.BaseHandler):
- @decorator.oauth_required
- def get(self):
- param=self.request.get('c')
- # post_url = param
- longurl = 'http://myapp.appspot.com/simple/?c=B62K4QBRR2DLRAGYN2GWPTGG6D425DMNEPFKDUARROCNI7QIGTCXGYHPEVL6GENQDBJDSYVINWJHI3267KIODPUKE7I4Y6KMML64WCCPPBRP6E7E4G7JL6IHOKF7N3N56L7V3XFGQJIJOF3VJ5MM6V4QD5CYF7GVN3JHB2FXR3EMRXOXDO4Z5WMTB6Y3WLLM5H7674ELU37KC==='
- scope='https://www.googleapis.com/auth/urlshortener')
- try:
- url = service.url()
- # Create a shortened URL by inserting the URL into the url collection.
- body = {'longUrl': longurl}
- resp = url.insert(body=body).execute()
- pprint.pprint(resp)
- short_url = resp['id']
- strin = short_url
- return self.response.write("<html><body><p>"+str(strin)+"</p></body></html>")
- except client.AccessTokenRefreshError:
- print ('The credentials have been revoked or expired, please re-run'
- 'the application to re-authorize')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement