My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Album  
jQuery.ajax supports Album API that fetches albums.
jQuery.ajax, jQuery.get, jQuery.getData
en, ja
Updated Feb 26, 2010 by nakajim...@gmail.com

opensocial-0.8 is required for datatype = "data" in jQuery.ajax

<Require feature="opensocial-0.8" />

Obtain an album list

It is possible to obtain a VIEWER album list using jQuery.ajax

  $.ajax({
    url: '/albums/@viewer/@self',
    data: {},
    dataType: 'data',
    success: function(albums) {
      $.each(albums, function(i, album) {
        console.info(album.id);
        console.info(album.title);
        console.info(album.description);
        console.info(album.thumbnailUrl);
        console.info(album.ownerId);
        console.info(album.mediaItemCount);
      });
    },
    error: function(xhr, status, e) {
      console.error(xhr, status, e);
    }
  });

This can also be done using jQuery.get

  $.get('/albums/@viewer/@self', {}, function(albums) {}, 'data');

The same can be done using jQuery.getData

  $.getData('/albums/@viewer/@self', {}, function(albums) {});

Specify filter criteria

An album ID can be specified using the URL path. The album ID can be specified by comma-delimiting.

  $.ajax({
    url: '/albums/@viewer/@self/1251149609611,1251414395296',
    data: {},
    dataType: 'data',
    success: function(albums) {
      $.each(albums, function(i, album) {
        console.info(album.id);
      });
    },
    error: function(xhr, status, e) {
      console.error(xhr, status, e);
    }
  });

Specify paging criteria

The paging criteria can be specified by using startIndex and count parameters. startIndex can be used with location to specify the position and with count to specify the number obtained. startIndex uses "0" to indicate item number 1. When abbreviated, numbers are used through to 20 items.

  $.ajax({
    url: '/albums/@viewer/@self',
    data: { startIndex: 0, count: 10 },
    dataType: 'data',
    success: function(albums) {},
    error: function(xhr, status, e) {}
  });

Furthermore, the startIndex and count parameters can also define the URL

  $.ajax({
    url: '/albums/@viewer/@self?startIndex=0&count=10',
    data: {},
    dataType: 'data',
    success: function(albums) {},
    error: function(xhr, status, e) {}
  });

Moreover, it is possible to retrieve location, the number of items per page, and the total number of items from the album list.

  $.ajax({
    url: '/albums/@viewer/@self',
    data: {},
    dataType: 'data',
    success: function(albums) {
      console.info(albums.startIndex);
      console.info(albums.itemsPerPage);
      console.info(albums.totalResults);
    },
    error: function(xhr, status, e) {}
  });

HTML Unescape

Album items are HTML unescapes with jQuery.ajax, jQuery.get, and jQuery.getData

Related Links


Sign in to add a comment
Powered by Google Project Hosting