Orkut Application Platform

The orkut Client Library - Photo Albums

Bruno Oliveira - Developer Relations
December 2010

This section of the guide explains how to perform common operations involving photo albums using the orkut Client Library. If you haven't read it yet, please read the Introduction to the Client Library first, since we'll assume you know how to perform the library and environment setup.


Albums and Photos

Each person can have photo albums, which are, intuitively enough collections of photos. Each album has a title and a description; each photo has a title, a thumbnail and a URL. The API does not serve photo data directly: instead, it returns the URL's where the photo data can be fetched from.

Using the API, it is possible to do almost all photo operations:

  • Create albums
  • Edit album properties
  • Share albums with friends
  • Delete albums
  • List photos in album
  • Edit photo properties
  • Upload a new photo to an album

Creating a New Photo Album

In order to programatically create a new photo album for the user who is logged in, all you have to do is use a CreateAlbumTx specifying the album title and description. The snippet below illustrates this operation.

CreateAlbumTx tx = orkad.getAlbumsTF().createAlbum(title,desc);
BatchTransaction btx = orkad.newBatch();

Naturally, you should check for errors (we're omitting that part here for brevity).

Listing Albums

You can also list the albums that a person has. This works not only for querying the albums of the user who is logged in, but also to query albums from other users. However, keep in mind that the data returned will depend on the privacy settings of the owner of the photos.

when you list albums, you only obtain the album properties, not the actual contents. In order to list the contents of an album, you must use a different transaction afterwards.

Here is an example snippet that lists the user's albums:

GetAlbumsTx tx = orkad.getAlbumsTF().getSelfAlbums();
tx.setCount(10);  // get only first 10 albums

BatchTransaction btx = orkad.newBatch();
say("Fetching first few albums...");

if (tx.hasError()) {
   say("*** Error!");

int i;
for (i = 0; i < tx.getAlbumCount(); i++) {
   Album album = tx.getAlbum(i);
   say("Album Title  : " + nullsafe(album.getTitle()));
   say("Description  : " + nullsafe(album.getDescription()));
   say("Thumbnail URL: " + nullsafe(album.getThumbnailUrl()));
   say("Album ID     : " + nullsafe(album.getId()));

As you can see, we submit a GetAlbumsTx transaction and then query its contents with getAlbumCount() and getAlbum(i) to get each individual album. Each of them comes with the properties listed above (title, description, thumbnail URL, album ID).

For more information about how to list the photos inside an album, please take a look at the Photo Transactions section.

Updating Albums

When we say update an album, what we mean is changing its title or description. If you want to manage an album's contents, this is not the transaction you are looking for. In that case, please refer to the Photo Transactions section.

To update an album's title or description, you must get the album normally using a GetAlbumsTx, then call setTitle and/or setDescription on it, and then resubmit it with an UpdateAlbumTx. The process is illustrated in the snippet below.

GetAlbumsTx tx = orkad.getAlbumsTF().getSelfAlbum(albumId);
BatchTransaction btx = orkad.newBatch();
say("Getting album...");

if (tx.hasError()) { say("*** Failed to get album."); return; }

if (tx.getAlbumCount() != 1) {
   say("*** Unexpected album count (expected 1): " +

Album album = tx.getAlbum(0);

say("Updating the album...");

btx = orkad.newBatch();
UpdateAlbumTx utx = orkad.getAlbumsTF().updateAlbum(album);

if (utx.hasError())
   say("*** Error updating album.");

Deleting an Album

In order to delete an album, use a DeleteAlbumTx that you can create using the deleteAlbum function of the album transaction factory on the OrkutAdapter. Its use is very straightforward:

DeleteAlbumTx tx = orkad.getAlbumsTF().deleteAlbum(albumId);
BatchTransaction btx = orkad.newBatch();

if (tx.hasError()) say("*** Error deleting album.");
else say("Deleted.");

Needless to say, be careful when deleting the user's albums! You definitely don't want a bug in your application to delete the user's favorite family photos.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.