OAuth 2.0 authorization borrowed from https://github.com/leocrawford/picasawebsync
#!/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
This comment has been minimized.
How is client_secrets supposed to be written? This is clearly missing something.