Gigya Job Openings

gm.getTopUsers JS

Skip to end of metadata
Go to start of metadata

Description

 

This method returns the top ranked users for a specified challenge. This method may be used for displaying a leaderboard of a challenge. Only users who have a name, email or provider will be returned.
 

Note: If you plan on integrating the Game Mechanic platform, we highly recommend reading the Game Mechanics Guide. Game Mechanics is a premium platform that requires separate activation. If Game Mechanics is not part of your site package please contact your Gigya Customer Engagement Executive or contact us by filling in a support form on our site. You can also access the support page by clicking "Support" on the upper menu of Gigya's site.

 

Note: This method is also supported in our REST API. If you wish to execute this method from your server, please refer to

REST API > gm.getTopUsers.

 

Syntax

 

 

Parameters

The following table lists the available parameters:

RequiredNameTypeDescription

challengestringThe challenge for which to return the top users. By default, if this parameter is not provided, then this method will return the top users of the default challenge (challenge="_default").
totalCountnumberThe total number of users to return in the response. The default value is 12, the minimum is 1, and the maximum is 100.
friendsCountnumberThe maximum number of random friends to retrieve. The default value is 3, the minimum is 0, and the maximum is 100.
Note: Fewer friends will be retrieved if the user's friends who are active in the challenge are less than the specified value.
includeSelfBooleanIndicate whether to include the user himself in the list. The default value is 'true'.
periodstringThe period for which to get the data. Valid values for this parameter are 'all' and '7days'. The default value is '7days'.
callbackfunction
A reference to a callback function. Gigya calls the specified function along with the results of the API method when the API method completes.
The callback function should be defined with the following signature: functionName(Response).
The "Response Object Data Members" table below provides specification of the data that is passed to the callback function.
contextobject
A developer-created object that is passed back unchanged to the application as one of the fields in the response object.
actionAttributesJSON objectThis parameter is used to retrieve the top ranked users according to a specific attribute, for example you can retrieve the top users only on the "Glee" page of a site, instead of the top users in the entire site. The action attribute is comprised of a single set of a key (category) and a value, e.g. {"tv-show":"glee"}. In order to use this option, you need to give action attributes to actions the user may perform on the site, such as sharing or commenting, and these action attributes will be used to filter. Read more here.

 

Response Object Data Members

FieldTypeDescription
errorCode integer The result code of the operation. Code '0' indicates success, any other number indicates failure. For a complete list of error codes, see the Response Codes and Errors table.
errorMessage string A short textual description of an error associated with the errorCode for logging purposes.
callId string Unique identifier of the transaction, for debugging purposes.
context object The context object passed by the application as a parameter to the API method, or null if no context object has been passed.
usersArrayAn array listing the top users. Each user is represented by an object that includes the following fields:
  • UID
  • name
  • photoURL
  • rank
    Users with the same number of points are ranked the same.
  • type 
    May be 'other', 'friend' or 'self'. 'other' indicates a user who is listed because he is one of the top users for the challenge. 'friend' indicates a user who is listed because he is the current user's friend. 'self' indicates the current user himself.
  • achievements
    List of the user's achievements, including the requested challenge and other challenges in which this user has reached at least level 1.  Each achievement is represented by an object that includes the following fields:
    • challengeID
    • badgeURL - the URL of the image file of the current level's badge.
    • pointsTotal - total accumulated points. This value cannot be less than zero.
    • points7Days- points accumulated during the past 7 days. This value cannot be less than zero.
    • level - the level that this user reached within this challenge.
    • levelTitle

 

Code Sample

function printResponse(response) {
    if ( response.errorCode == 0 ) {             
        if ( null!=response.users && response.users.length>0) {        
            var msg = 'The five top ranked users are:\n\n';        
            for (var index in response.users) {
                var currUser = response.users[index];
                msg += currUser ['name']+ ' - ' + currUser ['rank']+ '\n' ;                 
            }            
            alert(msg);
        }
        else {
            alert('No data returned');
        }
    }
    else {
        alert('Error :' + response.errorMessage);
    }
};   

var params = { 
	callback:printResponse,
	totalCount: 5
};

gigya.gm.getTopUsers(params); 

Notes:

  • This sample is not meant to be fully functional code. For brevity's sake, only the code required for demonstrating the API call itself is presented.
  • To run the code on your own domain, add your Gigya API key to the gigya.js URL. A Gigya API key can be obtained on the Site Dashboard page on Gigya's website. Please make sure that the domain from which you are loading the page is the same domain name that you used for generating the API key.
  • In some cases it is necessary to connect/login the user to a provider ? prior to calling the API method. You can learn more in the Social Login guide.