Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 55 lines (41 sloc) 1.84 KB
import os
import gdata
import gdata.photos.service
import gdata.media
import gdata.geo
import gdata.gauth
import webbrowser
from datetime import datetime, timedelta
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
def OAuth2Login(client_secrets, credential_store, email):
scope='https://picasaweb.google.com/data/'
user_agent='picasawebuploader'
storage = Storage(credential_store)
credentials = storage.get()
if credentials is None or credentials.invalid:
flow = flow_from_clientsecrets(client_secrets, scope=scope, redirect_uri='urn:ietf:wg:oauth:2.0:oob')
uri = flow.step1_get_authorize_url()
webbrowser.open(uri)
code = raw_input('Enter the authentication code: ').strip()
credentials = flow.step2_exchange(code)
if (credentials.token_expiry - datetime.utcnow()) < timedelta(minutes=5):
http = httplib2.Http()
http = credentials.authorize(http)
credentials.refresh(http)
storage.put(credentials)
gd_client = gdata.photos.service.PhotosService(source=user_agent,
email=email,
additional_headers={'Authorization' : 'Bearer %s' % credentials.access_token})
return gd_client
if __name__ == '__main__':
email = "kevin.osborn@gmail.com"
# options for oauth2 login
configdir = os.path.expanduser('./')
client_secrets = os.path.join(configdir, 'OpenSelfie.json')
#client_secrets = os.path.join(configdir, 'client_secrets.json')
credential_store = os.path.join(configdir, 'credentials.dat')
gd_client = OAuth2Login(client_secrets, credential_store, email)
albums = gd_client.GetUserFeed()
for album in albums.entry:
print 'title %s id = %s' %(album.title.text, album.gphoto_id.text)