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.

Swift:

  • let userName = "user_123456"
    let found : KiiUser
    
    do{
      // Find a user by name.
      found = try KiiUser.find(byUsernameSynchronous: userName)
    }catch(let error as NSError){
      // Handle the error.
      return
    }
  • let userName = "user_123456"
    
    // Find a user by name.
    KiiUser.find(byUsername: userName) { (user :KiiUser?, error : Error?) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    }

Objective-C:

  • NSString *username = @"user_123456";
    NSError *error = nil;
    
    // Find a user by name.
    KiiUser *found = [KiiUser findUserByUsernameSynchronous:username
                                                  withError:&error];
    if (error != nil) {
      // Handle the error.
      return;
    }
  • NSString *username = @"user_123456";
    
    // Find a user by name.
    [KiiUser findUserByUsername:username
                      withBlock:^(KiiUser *user, NSError *error) {
      if (error != nil) {
        // 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.

Swift:

  • let email = "user_123456@example.com"
    let found : KiiUser
    
    do{
      // Find a user by email address.
      found = try KiiUser.find(byEmailSynchronous: email)
    }catch(let error as NSError){
      // Handle the error.
      return
    }
  • let email = "user_123456@example.com"
    
    // Find a user by email address.
    KiiUser.find(byEmail: email) { (user :KiiUser?, error : Error?) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    }

Objective-C:

  • NSString *email = @"user_123456@example.com";
    NSError *error = nil;
    
    // Find a user by email address.
    KiiUser *found = [KiiUser findUserByEmailSynchronous:email
                                               withError:&error];
    if (error != nil) {
      // Handle the error.
      return;
    }
  • NSString *email = @"user_123456@example.com";
    
    // Find a user by email address.
    [KiiUser findUserByEmail:email
                   withBlock:^(KiiUser *user, NSError *error) {
      if (error != nil) {
        // Handle the error.
        return;
      }
    }];

Retrieve user attributes with phone number

The following sample shows how you can retrieve a user data by his/her phone number. You must specify the verified phone number. The user needs to be logged in for accessing the data.

Note that you must specify the phone number in an international phone number format (starting with + and your country code).

Swift:

  • let phone = "+819012345678"
    let found : KiiUser
    
    do{
      // Find a user by phone number.
      found = try KiiUser.find(byPhoneSynchronous: phone)
    }catch(let error as NSError){
      // Handle the error.
      return
    }
  • let phone = "+819012345678"
    
    // Find a user by phone number.
    KiiUser.find(byPhone: phone) { (user :KiiUser?, error : Error?) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    }

Objective-C:

  • NSString *phone = @"+819012345678";
    NSError *error = nil;
    
    // Find a user by phone number.
    KiiUser *found = [KiiUser findUserByPhoneSynchronous:phone
                                               withError:&error];
    if (error != nil) {
      // Handle the error.
      return;
    }
  • NSString *phone = @"+819012345678";
    
    // Find a user by phone number.
    [KiiUser findUserByPhone:phone
                   withBlock:^(KiiUser *user, NSError *error) {
      if (error != nil) {
        // 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.

Swift:

  • let userUri = "Set the URI of an existing user here"
    
    // Instantiate a user.
    let userWithURI = KiiUser(uri: userUri)
    
    do{
      // Refresh the user.
      try userWithURI.refreshSynchronous()
    } catch let error as NSError {
      // Handle the error.
      return
    }
  • let userUri = "Set the URI of an existing user here"
    
    // Instantiate a user.
    let userWithURI = KiiUser(uri: userUri)
    
    // Refresh the user.
    userWithURI.refresh { (user :KiiUser?, error : Error?) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    }

Objective-C:

  • NSString *userURI = @"Set the URI of an existing user here";
    
    // Instantiate a user.
    KiiUser *userWithURI = [KiiUser userWithURI:userURI];
    
    NSError *error = nil;
    
    // Refresh the user.
    [userWithURI refreshSynchronous:&error];
    if (error != nil) {
      // Handle the error.
      return;
    }
  • NSString *userURI = @"Set the URI of an existing user here";
    
    // Instantiate a user.
    KiiUser *userWithURI = [KiiUser userWithURI:userURI];
    
    // Refresh the user.
    [userWithURI refreshWithBlock:^(KiiUser *user, NSError *error) {
      if (error != nil) {
        // 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.

Swift:

  • let userID = "Set the ID of an existing user here"
    
    // Instantiate a user.
    let userWithID = KiiUser(uri: userID)
    
    do{
      // Refresh the user.
      try userWithID.refreshSynchronous()
    } catch let error as NSError {
      // Handle the error.
      return
    }
  • let userID = "Set the ID of an existing user here"
    
    // Instantiate a user.
    let userWithID = KiiUser(uri: userID)
    
    // Refresh the user.
    userWithID.refresh { (user :KiiUser?, error : Error?) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    }

Objective-C:

  • NSString *userID = @"Set the ID of an existing user here";
    
    // Instantiate a user.
    KiiUser *userWithID = [KiiUser userWithID:userID];
    
    NSError *error = nil;
    
    // Refresh the user.
    [userWithID refreshSynchronous:&error];
    if (error != nil) {
      // Handle the error.
      return;
    }
  • NSString *userID = @"Set the ID of an existing user here";
    
    // Instantiate a user.
    KiiUser *userWithID = [KiiUser userWithID:userID];
    
    // Refresh the user.
    [userWithID refreshWithBlock:^(KiiUser *user, NSError *error) {
      if (error != nil) {
        // Handle the error.
        return;
      }
    }];