Created
June 22, 2015 09:59
-
-
Save hrpunio/da9d1a7c49a07a27d874 to your computer and use it in GitHub Desktop.
OAuth 2.0 authorization borrowed from https://github.com/leocrawford/picasawebsync
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import time | |
import httplib2 | |
## https://github.com/google/oauth2client | |
## installed with pip install --upgrade oauth2client (or some other way) | |
from oauth2client import client | |
def oauthLogin(): | |
# using http://stackoverflow.com/questions/20248555/list-of-spreadsheets-gdata-oauth2/29157967#29157967 | |
from oauth2client.file import Storage | |
filename = os.path.join(os.path.expanduser('~'), ".picasawebsync") | |
client_secrets = os.path.join(os.path.expanduser('~'), ".config", "picasawebsync.json") | |
storage = Storage(filename) | |
credentials = storage.get() | |
if credentials is None or credentials.invalid: | |
flow = client.flow_from_clientsecrets(client_secrets, | |
scope='https://picasaweb.google.com/data/', | |
redirect_uri='urn:ietf:wg:oauth:2.0:oob') | |
auth_uri = flow.step1_get_authorize_url() | |
print 'Authorization URL: %s' % auth_uri | |
auth_code = raw_input('Enter the auth code: ') | |
credentials = flow.step2_exchange(auth_code) | |
storage.put(credentials) | |
if credentials.access_token_expired: | |
credentials.refresh(httplib2.Http()) | |
return credentials.access_token | |
# start of the program | |
gd_client = oauthLogin() | |
print '%s' % gd_client |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How is client_secrets supposed to be written? This is clearly missing something.