Skip to content

Instantly share code, notes, and snippets.

@hrpunio
Created June 22, 2015 09:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hrpunio/da9d1a7c49a07a27d874 to your computer and use it in GitHub Desktop.
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
@goodevilgenius
Copy link

raise InvalidClientSecretsError('File not found: "%s"' % filename)

How is client_secrets supposed to be written? This is clearly missing something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment