2

I have been using Google's Picasa API successfully from last 6 months or so. Today I have started getting an error

    raise GooglePhotosException(e.args[0])
GooglePhotosException: (403, 'Forbidden', 'Authorization required')

I checked my credentials.

    self.gd_client = gdata.photos.service.PhotosService()
    self.gd_client.email = EmailOfTheUploadingPictureAccount
    self.gd_client.password = PasswordOfTheAccount
    self.gd_client.source = 'destipak' #Not sure about that
    self.feed_url = "/data/feed/api/user/"
    self.entry_url = "/data/entry/api/user/"
    self.gd_client.ProgrammaticLogin() 

Everything was working well since yesterday. Anyone has any clues?

EDIT

Example given on Picasa for python is also not working. URL

#!/usr/bin/python2.5

import gdata.photos.service
import gdata.media
import gdata.geo

gd_client = gdata.photos.service.PhotosService()
gd_client.email = '=change='     # Set your Picasaweb e-mail address...
gd_client.password = '=change='  # ... and password
gd_client.source = 'api-sample-google-com'
gd_client.ProgrammaticLogin()

albums = gd_client.GetUserFeed()
for album in albums.entry:
  print 'Album: %s (%s)' % (album.title.text, album.numphotos.text)

  photos = gd_client.GetFeed('/data/feed/api/user/default/albumid/%s?kind=photo' % (album.gphoto_id.text))
  for photo in photos.entry:
    print '  Photo:', photo.title.text

    tags = gd_client.GetFeed('/data/feed/api/user/default/albumid/%s/photoid/%s?kind=tag' % (album.gphoto_id.text, photo.gphoto_id.text))
    for tag in tags.entry:
      print '    Tag:', tag.title.text

    comments = gd_client.GetFeed('/data/feed/api/user/default/albumid/%s/photoid/%s?kind=comment' % (album.gphoto_id.text, photo.gphoto_id.text))
    for comment in comments.entry:
      print '    Comment:', comment.content.text

EDIT 2

Full traceback

Traceback (most recent call last):
  File "/Users/mac/Picasa_API.py", line 158, in <module>
    check_api()
  File "/Users/mac/Picasa_API.py", line 140, in check_api
    albums = gd_client.GetUserFeed()
  File "/Users/mac/destipak/env/lib/python2.7/site-packages/gdata/photos/service.py", line 235, in GetUserFeed
    return self.GetFeed(uri, limit=limit)
  File "/Users/mac/destipak/env/lib/python2.7/site-packages/gdata/photos/service.py", line 180, in GetFeed
    raise GooglePhotosException(e.args[0])
gdata.photos.service.GooglePhotosException: (403, 'Forbidden', 'Authorization required')
2
  • Can you log in to any Google services with that account? The documents also specify that the "source" parameter needs to be in the form company_id-app_name-app_version. gdata-python-client.googlecode.com/hg/src/gdata/service.py Commented May 27, 2015 at 6:07
  • Yes i can login to that account using the ID/Password. Not sure about the source.. Commented May 27, 2015 at 6:17

2 Answers 2

5

Here is the code I use to get OAuth2 authentication working with Picasa. First you need to create a client ID through the Google Developer Console: at https://console.developers.google.com/ and then you must download the client secrets as JSON and pass the filename to OAuth2Login.

The first time you run this code, you will have to authorize the client through your web browser, and paste the code you get there into the application. The credentials are then stored in the file specified by credential_store.

def OAuth2Login(client_secrets, credential_store, email):
    scope='https://picasaweb.google.com/data/'
    user_agent='myapp'

    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)
        storage.put(credentials)

    if (credentials.token_expiry - datetime.utcnow()) < timedelta(minutes=5):
        http = httplib2.Http()
        http = credentials.authorize(http)
        credentials.refresh(http)

    gd_client = gdata.photos.service.PhotosService(source=user_agent,
                                               email=email,
                                               additional_headers={'Authorization' : 'Bearer %s' % credentials.access_token})

    return gd_client
Sign up to request clarification or add additional context in comments.

2 Comments

I want to authenticate via Service Login, i do not want to authenticate via browser. I want to upload photos to my own account (single)
The browser is used only once to get the OAuth2 token. I am using this myself in a modified version of picasawebuploader, which is found here: github.com/MicOestergaard/picasawebuploader
0

I ran into this as well. Seems like email/password authentication has been turned off, and we need to switch to OAuth2. See https://groups.google.com/forum/#!topic/Google-Picasa-Data-API/4meiAJ40l3E

1 Comment

Do you have any resource or link where I can start looking for OAuth2?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.