My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
MediaItem  
jQuery.ajax supports Album API that fetches photos and other media items.
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 a Photo List for an Album

It is possible to obtain a photo list of a VIEWER album using jQuery.ajax. The album ID can be specified.

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

This can also be done using jQuery.get

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

The same can be done using jQuery.getData

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

Specify filter criteria

A photo ID can be specified using the URL path. The photo ID can be specified by comma-delimiting.

  $.ajax({
    url: '/mediaitems/@viewer/@self/1251149609611/147988,662963',
    data: {},
    dataType: 'data',
    success: function(mediaitems) {
      $.each(mediaitems, function(i, mediaitem) {
        console.info(mediaitem.id);
        console.info(mediaitem.url);
        console.info(mediaitem.title);
        console.info(mediaitem.description);
        console.info(mediaitem.thumbnailUrl);
        console.info(mediaitem.albumId);
      });
    },
    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: '/mediaitems/@viewer/@self/1251149609611',
    data: { startIndex: 0, count: 10 },
    dataType: 'data',
    success: function(mediaitems) {},
    error: function(xhr, status, e) {}
  });

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

  $.ajax({
    url: '/mediaitems/@viewer/@self/1251149609611?startIndex=0&count=10',
    data: {},
    dataType: 'data',
    success: function(mediaitems) {},
    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: '/mediaitems/@viewer/@self/1251149609611',
    data: {},
    dataType: 'data',
    success: function(mediaitems) {
      console.info(mediaitems.startIndex);
      console.info(mediaitems.itemsPerPage);
      console.info(mediaitems.totalResults);
    },
    error: function(xhr, status, e) {}
  });

HTML Unescape

Photo 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