views:

15

answers:

1

I am trying to write a pager from my application which require to get the total number of albums. I can fetch all albums from the orkut but it slow down the transfer rate since I only need the total not the data in the albums.

Does opensocial v9 has a function I can check how many albums a viewer has? or maybe I fetch only the ID of the albums so I can minimize the transfer time

A: 

Opensocial suports pagination by providing developers the ability to add startIndex and count parameters to DataRequests ( and other *Requests). If developer does not supply a count parameters, its detault is 20, and as you guess, when a startIndex parameter isnt supplied, it defautls to 0(zero).

Response you get must be something like:

{
  "startIndex": 0,
  "totalResults": 120,
  "entry": [
    ....
  ]
}

Here, totalResults is the total number of albums, not the returned album count. You can use totalResults to calculate your page count and prepare your pagination.

Update:
opensocial.DataRequest.MediaItemsField.MAX field probably used while making MediaItemRequests, however to make a album list AlbumRequest should be used. you can limit the number of albums fetched in this pipeline

<os:AlbumsRequest key='myalbums' userid="@viewer" groupid="@self" />

by adding a count parameter, such as:

<os:AlbumsRequest key='myalbums' userid="@viewer" groupid="@self" count="5"/>

this album request fetches at max 5 albums of viewer. the resulting json would be:

{
  "startIndex": 0,
  "totalResults": ....here total number of albums....,
  "entry": [
    ....here at max 5 albums....
  ]
}

Here you can get total number of album by calling myalbums.totalResults.

feridcelik
Do you mean the parameter opensocial.DataRequest.MediaItemsField.MAX = something values.... and use the response collections.getTotalSize.
Simon
Oh sorry, I need for albums as well as photos. I used the DataRequest.send and get the response object but I couldn't find the totalResults instead I have a Collection object for albums that contain a function 'getTotalSize()'. I assume the 'getTotalSize' is the function I really wanted but it wasn't. It gave me 5 fetched albums.
Simon
can I see related part of your code?
feridcelik