Retrieving Other User's Data

You can access other user's attributes by specifying their username, email address or phone number.

Retrievable user attributes

You can only read other user's attributes. The amount of user attributes retrievable depends on the application setting (the "Expose Full User Data To Others" option). See User Attributes for the further discussion.

To learn how you can change the application setting, see Configuring User Attribute Disclosure Level

Retrieve other user's attributes

Retrieve user attributes with username

The following sample shows you how to retrieve user data by username. The user needs to be logged in for accessing the data.

  • var username = "user_123456";
    
    // Find a user by name.
    KiiUser.findUserByUsername(username).then(
      function(foundUser) {
        // Do something.
      }
    ).catch(
      function(error) {
        // Handle the error.
        var errorString = error.message;
      }
    );
  • var username = "user_123456";
    
    // Find a user by name.
    KiiUser.findUserByUsername(username, {
      success: function(foundUser) {
        // Do something.
      },
      failure: function(errorString) {
        // Handle the error.
      }
    });

Retrieve user attributes with email address

The following sample shows you how to retrieve user data by email address. Note that you must specify the verified email address. The user needs to be logged in for accessing the data.

  • var emailAddress = "user_123456@example.com";
    
    // Find a user by email address.
    KiiUser.findUserByEmail(emailAddress).then(
      function(foundUser) {
        // Do something.
      }
    ).catch(
      function(error) {
        // Handle the error.
        var errorString = error.message;
      }
    );
  • var emailAddress = "user_123456@example.com";
    
    // Find a user by email address.
    KiiUser.findUserByEmail(emailAddress, {
      success: function(foundUser) {
        // Do something.
      },
      failure: function(errorString) {
        // Handle the error.
      }
    });

Retrieve user attributes with phone number

The following sample shows you how to retrieve user data by phone number. Note that you must specify a verified phone number in an international format (starting with + and your country code). The user needs to be logged in for accessing the data.

  • var phoneNumber = "+819012345678";
    
    // Find a user by phone number.
    KiiUser.findUserByPhone(phoneNumber).then(
      function(foundUser) {
        // Do something.
      }
    ).catch(
      function(error) {
        // Handle the error.
        var errorString = error.message;
      }
    );
  • var phoneNumber = "+819012345678";
    
    // Find a user by phone number.
    KiiUser.findUserByPhone(phoneNumber, {
      success: function(foundUser) {
        // Do something.
      },
      failure: function(errorString) {
        // Handle the error.
      }
    });

Retrieve user attributes with URI

The following sample shows you how to retrieve user data by URI. The user needs to be logged in for accessing the data.

  • // Instantiate a user.
    var user = KiiUser.userWithURI("Set the URI of an existing user here");
    
    // Refresh the user.
    user.refresh().then(
      function(theUser) {
        // Do something.
      }
    ).catch(
      function(error) {
        // Handle the error.
        var theUser = error.target;
        var errorString = error.message;
      }
    );
  • // Instantiate a user.
    var user = KiiUser.userWithURI("Set the URI of an existing user here");
    
    // Refresh the user.
    user.refresh({
      success: function(theUser) {
        // Do something.
      },
      failure: function(theUser, errorString) {
        // Handle the error.
      }
    });

Retrieve user attributes with userID

The following sample shows you how to retrieve user data with user ID. The user needs to be logged in for accessing the data.

  • // Instantiate a user.
    var user = KiiUser.userWithID("put existing user ID here");
    
    // Refresh the user.
    user.refresh().then(
      function(theUser) {
        // Do something.
      }
    ).catch(
      function(error) {
        // Handle the error.
        var theUser = error.target;
        var errorString = error.message;
      }
    );
  • // Instantiate a user.
    var user = KiiUser.userWithID("put existing user ID here");
    
    // Refresh the user.
    user.refresh({
      success: function(theUser) {
        // Do something.
      },
      failure: function(theUser, errorString) {
        // Handle the error.
      }
    });