i am trying to access/retrieve private Picasa albums, photo details from
albums and creating a new album using PicasaWeb Java API.
PFB the code:
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.util.List;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.gdata.client.photos.PicasawebService;
import com.google.gdata.data.PlainTextConstruct;
import com.google.gdata.data.media.MediaFileSource;
import com.google.gdata.data.photos.AlbumEntry;
import com.google.gdata.data.photos.AlbumFeed;
import com.google.gdata.data.photos.PhotoEntry;
import com.google.gdata.data.photos.UserFeed;
import com.google.gdata.util.ServiceException;
public class PicasaTest{
public static void main(String[] args) throws MalformedURLException,
GeneralSecurityException, IOException, ServiceException {
URL postUrl = new URL(
"https://picasaweb.google.com/data/feed/api/user/<UID>?&v=2");
File p12 = new File("PhotoGallery.p12");
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
String[] SCOPESArray = {"https://picasaweb.google.com/data",
"http://picasaweb.google.com/data/feed/api"};
final List SCOPES = Arrays.asList(SCOPESArray);
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId("<serviceaccountidfromdevconsole>")
.setServiceAccountScopes(SCOPES)
.setServiceAccountPrivateKeyFromP12File(p12)
.build();
credential.refreshToken();
PicasawebService myService = new PicasawebService("<UID>");
myService.setOAuth2Credentials(credential);
System.out.println("Token :"+credential.getAccessToken());
UserFeed myUserFeed = myService.getFeed(new URL(postUrl+"&access_token="
+credential.getAccessToken()), UserFeed.class);
for (AlbumEntry myAlbum : myUserFeed.getAlbumEntries()) {
System.out.println("Album Name :"+myAlbum.getTitle().getPlainText());
System.out.println("Access:"+myAlbum.getAccess());
System.out.println("Id :"+myAlbum.getId());
System.out.println("XML :"+myAlbum.getXmlBlob());
}
credential.refreshToken();
/*Adding new album*/
PicasawebService addService = new PicasawebService("<UID>");
addService.setOAuth2Credentials(credential);
AlbumEntry myAlbum = new AlbumEntry();
myAlbum.setTitle(new PlainTextConstruct("My Album"));
myAlbum.setDescription(new PlainTextConstruct("My trip to delhi was
delightful!"));
AlbumEntry insertedEntry = addService.insert(postUrl, myAlbum);
URL albumPostUrl = new URL(
"https://picasaweb.google.com/data/feed/api/user/<UID>/albumid/<albumID>");
PhotoEntry myPhoto = new PhotoEntry();
myPhoto.setTitle(new PlainTextConstruct("Puppies FTW"));
myPhoto.setDescription(new PlainTextConstruct("Puppies are the
greatest."));
myPhoto.setClient("myClientName");
MediaFileSource myMedia = new MediaFileSource(new File("puppies.jpg"),
"image/jpeg");
myPhoto.setMediaSource(myMedia);
PhotoEntry returnedPhoto = myService.insert(albumPostUrl, myPhoto);
}
}
i am able to retrieve only the public albums but not the private albums and
while creating new album its giving the below authorization error.
**Exception in thread "main"
com.google.gdata.util.ServiceForbiddenException: Forbidden
Not authorized to modify this resource.**
Can any one please tell me where i am going wrong and what is the problem
in above the code.
if any one has done this (Google Picasa java web API authentication,
retrieving private album list and created new albums), can you please share
the steps you did to achieve it.
--
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.