Since this was my first program using Google Data APIs, it took me longer to set up a working environment than it did to actually write the Java code. The getting-started guide is here. For my case, I needed as external dependencies 1) JavaMail and 2) the JavaBeansActivation Framework, both of which most open-source-Java developers already have sitting around somewhere convenient. Then I grabbed the latest Google Data Java Client libraries, unzipped, and put all of the jars in gdata/java/lib and gdata/java/deps on the classpath of my project.
From there, the code was very straightforward. Note the placeholders for Google username and password.
import java.net.URL;
import java.util.List;
import com.google.gdata.client.photos.PicasawebService;
import com.google.gdata.data.photos.GphotoEntry;
import com.google.gdata.data.photos.UserFeed;
/**
* Short script to download links to all of my Picasa
* Web Albums. This includes private/public/protected
* access levels.
*
* @author Scott McMaster (smcmaster@acm.org)
*
*/
public class DownloadPicasaWebAlbumLinks {
private static final String USERNAME = "NOTMYREALUSERNAME";
private static final String PASSWORD = "NOTMYREALPASSWORD";
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
PicasawebService myService = new PicasawebService(
"Download Album Links");
myService.setUserCredentials(USERNAME, PASSWORD);
URL albumFeedUrl = new URL(
"http://picasaweb.google.com/data/feed/api/user/" + USERNAME
+ "?kind=album");
UserFeed albumFeed = myService.getFeed(albumFeedUrl, UserFeed.class);
List albums = albumFeed.getEntries();
for (GphotoEntry album : albums) {
System.out.println(album.getHtmlLink().getHref());
}
}
}
For "unlisted" albums, this will print out, for each album, the same link you get if you click "Link to this album" in the UI.
0 comments:
Post a Comment