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.

  • String username = "user_123456";
    
    try {
      // Find a user by name.
      KiiUser found = KiiUser.findUserByUserName(username);
    } catch (IOException e) {
      // Handle the error.
    } catch (AppException e) {
      // Handle the error.
    }
  • String username = "user_123456";
    
    // Find a user by name.
    KiiUser.findUserByUserName(username, new KiiUserCallBack() {
      @Override
      public void onFindCompleted(int token, KiiUser caller, KiiUser found, Exception exception) {
        if (exception != null) {
          // Handle the error.
          return;
        }
      }
    });

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.

  • String email_address = "user_123456@example.com";
    
    try {
      // Find a user by email address.
      KiiUser found = KiiUser.findUserByEmail(email_address);
    } catch (IOException e) {
      // Handle the error.
    } catch (AppException e) {
      // Handle the error.
    }
  • String email_address = "user_123456@example.com";
    
    // Find a user by email address.
    KiiUser.findUserByEmail(email_address, new KiiUserCallBack() {
      @Override
      public void onFindCompleted(int token, KiiUser caller, KiiUser found, Exception exception) {
        if (exception != null) {
          // Handle the error.
          return;
        }
      }
    });

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.

  • String phone_number = "+819012345678";
    
    try {
      // Find a user by phone number.
      KiiUser found = KiiUser.findUserByPhone(phone_number);
    } catch (IOException e) {
      // Handle the error.
    } catch (AppException e) {
      // Handle the error.
    }
  • String phone_number = "+819012345678";
    
    // Find a user by phone number.
    KiiUser.findUserByPhone(phone_number, new KiiUserCallBack() {
      @Override
      public void onFindCompleted(int token, KiiUser caller, KiiUser found, Exception exception) {
        if (exception != null) {
          // Handle the error.
          return;
        }
      }
    });

Retrieve user attributes with URI

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

  • Uri uri = Uri.parse("Set the URI of an existing user here");
    
    try {
      // Instantiate a user.
      KiiUser user = KiiUser.createByUri(uri);
    
      // Refresh the user.
      user.refresh();
    } catch (IOException e) {
      // Handle the error.
    } catch (AppException e) {
      // Handle the error.
    }
  • Uri uri = Uri.parse("Set the URI of an existing user here");
    
    // Instantiate a user.
    final KiiUser user = KiiUser.createByUri(uri);
    
    // Refresh the user.
    user.refresh(new KiiUserCallBack() {
      @Override
      public void onRefreshCompleted(int token, Exception exception) {
        if (exception != null) {
          // Handle the error.
          return;
        }
      }
    });

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.

  • String userID = "Set the ID of an existing user here";
    
    try {
      // Instantiate a user.
      KiiUser user = KiiUser.userWithID(userID);
    
      // Refresh the user.
      user.refresh();
    } catch (IOException e) {
      // Handle the error.
    } catch (AppException e) {
      // Handle the error.
    }
  • String userID = "Set the ID of an existing user here";
    
    // Instantiate a user.
    final KiiUser user = KiiUser.userWithID(userID);
    
    // Refresh the user.
    user.refresh(new KiiUserCallBack() {
      @Override
      public void onRefreshCompleted(int token, Exception exception) {
        if (exception != null) {
          // Handle the error.
          return;
        }
      }
    });