My previously working picasawebservice code failed when Google switched to 
the OAuth 2 authentication.


I have modified the code to use a Goodle credential for which I needed to 
set up a Service Account.


Although no errors are returned when I add the credential to the 
PicasawebService object I cannot add any photos to my album.


I have obtained a list of albums using the url 
https://picasaweb.google.com/data/feed/api/user/xxx?kind=album but it only 
returns the public Profile Album, not the other albums on the account, also 
when I use the album id returned by the feed I get an "Access forbidden" 
error when I try to insert a photo. (xxx - I have used both the user id and 
the email address for the account and get the same result in each case).


I have been able to establish the album ids for the private albums on the 
account but using these also failed when attempting an insert.


The code is


     String emailAddress = "-- the email address from the Google Developers 
console for the credential --";
      JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
      GoogleCredential credential = null;
      try {
        HttpTransport httpTransport = 
GoogleNetHttpTransport.newTrustedTransport();
        String[] SCOPESArray = 
{"https://picasaweb.google.com/data","http://picasaweb.google.com/data/feed/api"};
        final List<String> SCOPES = Arrays.asList(SCOPESArray);

        credential = new GoogleCredential.Builder()
            .setTransport(httpTransport)
            .setJsonFactory(JSON_FACTORY)
            .setServiceAccountId(emailAddress)
            .setServiceAccountPrivateKeyFromP12File(new File("-- the p12 key 
file --"))
            .setServiceAccountScopes(SCOPES)
            .build();
      } catch (GeneralSecurityException ex) {
        logger.error("processUpload: Error getting Google credential " + 
accountBean.getZuzzAccountId() + " - " + accountBean.getAccountTitle() + " - " 
+ ex.toString());
        uploadMessage = "Error getting a connection to the photo store - please 
see the administratior";
        return;
      }    

      credential.refreshToken();
      String accessToken = credential.getAccessToken();

      PicasawebService myService = new PicasawebService("Zuzz-ZuzzClub-1.2");
      myService.setOAuth2Credentials(credential);

      URL albumPostUrl = null;
      try {
        albumPostUrl = new 
URL("https://picasaweb.google.com/data/feed/api/user/--  my user id 
--/albumid/-- album id returned from feed --");
      } catch (MalformedURLException ex) {
        logger.error("processUpload: Error getting album post url for account " 
+ accountBean.getZuzzAccountId() + " - " + accountBean.getAccountTitle() + " - 
" + ex.toString());
        uploadMessage = "Error getting a connection to the photo store - please 
see the administratior";
        return;
      }

      PhotoEntry myPhoto = new PhotoEntry();
      myPhoto.setTitle(new PlainTextConstruct(fileName));
      myPhoto.setDescription(new 
PlainTextConstruct(months.get(Integer.valueOf(editionMonth).intValue()) + " " + 
editionYear));
      myPhoto.setClient("ZuzzClub");

      MediaStreamSource myMedia = null;
      myMedia = new MediaStreamSource(imageInStream,"image/jpeg");
      if (myMedia == null) {
        logger.error("processUpload: Error generating the thumbnail photo - 
null media source for account " + accountBean.getZuzzAccountId() + " - " + 
accountBean.getAccountTitle());
        uploadMessage = "Error generating the thumbnail photo - please see the 
administratior";
        return;
      }
      myPhoto.setMediaSource(myMedia);

      thumbNailUrl = null;
      try {
        PhotoEntry returnedPhoto = myService.insert(albumPostUrl, myPhoto);
        ArrayList<MediaContent> mediaContent = (ArrayList<MediaContent>) 
returnedPhoto.getMediaContents();
        thumbNailUrl = mediaContent.get(0).getUrl();
      } catch (IOException ex) {
        logger.error("processUpload: Error adding photo to Photo store for 
account " + accountBean.getZuzzAccountId() + " - " + 
accountBean.getAccountTitle() + " - " + ex.toString());
        uploadMessage = "Error generating the thumbnail photo - please see the 
administratior";
        return;
      } catch (ServiceException ex) {
        logger.error("processUpload: Error adding photo to Photo store for 
account " + accountBean.getZuzzAccountId() + " - " + 
accountBean.getAccountTitle() + " - " + ex.toString());
        uploadMessage = "Error generating the thumbnail photo - please see the 
administratior";
        return;
      } finally {
        imageInStream.close();
      }


The problem appears to be that the authentication has not granted 
permission to perform the insert, however the service account is set to 
"Can edit" in the Google Developers Console.

Is there a way of finding out what permissions the service has after the 
credential has been applied?

Has anyone managed to add photos to a Picasa album after the authentication 
change?


-- 
You received this message because you are subscribed to the Google Groups 
"Google Picasa Web Albums API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-picasa-data-api.
For more options, visit https://groups.google.com/d/optout.

Reply via email to