Getting a Member List of a Group

A group owner and members can get a list of members of the group as below.

Note that the KiiUser instance returned by the method only contains the ID. Execute the refresh() method to get the user's latest information from Kii Cloud.

If the returned user is different from the logged-in user, available user information is limited. For more information, see User Attributes.

The following sample code shows how to get a list of members of a group:

  • function refreshAllMembers(members) {
      var list = members.concat();
      var refreshRecurr = function() {
        var member = list.shift();
        if (member === void(0)) {
          return Promise.resolve(members);
        }
        return member.refresh().then(refreshRecurr);
      };
      return refreshRecurr();
    }
    
    // Get a list of members of the group.
    group.getMemberList().then(
      function(params) {
        var group = params[0];
        var memberList = params[1];
    
        // Refresh the members to retrieve the latest data from Kii Cloud.
        return refreshAllMembers(memberList);
      }
    ).then(
      function(members) {
        // Do something.
        for (var i = 0; i < members.length; i++) {
          var m = members[i];
          console.log("DisplayName: %s", m.getDisplayName());
        }
      }
    ).catch(
      function(error) {
        // Handle the error.
    
        // Get the group for the failed getMemberList() method.
        var thrGroup = error.target;
        // Get the user for the failed refresh() method.
        var theUser = error.target;
        // Get the error message.
        var errorString = error.message;
      }
    );
  • function refreshMembers(members, callbacks) {
      var list = members.concat();
      var member = list.shift();
      if (member === void(0)) {
        callbacks.success();
        return;
      }
    
      member.refresh({
        success: function(theUser) {
          refreshMembers(list, callbacks);
        },
        failure: function(theUser, errorString) {
          callbacks.failure(theUser, errorString);
        }
      });
    }
    
    // Get a list of members of the group.
    group.getMemberList({
      success: function(theGroup, memberList) {
        // Refresh the members to retrieve the latest data from Kii Cloud.
        refreshMembers(memberList, {
          success: function() {
            // Do something.
            for (var i = 0; i < memberList.length; i++) {
              var m = memberList[i];
              console.log("DisplayName: %s", m.getDisplayName());
            }
          },
          failure: function(theUser, errorString) {
            // Handle the error.
          }
        });
      },
      failure: function(theGroup, errorString) {
        // Handle the error.
      }
    });