I am trying to write a pager from my application which require to get the total number 开发者_如何学Goof 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
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
.
精彩评论