Skip to content

Get and Find Users

Get Current User

To get an instance of current user:

GetSocial.getCurrentUser()
GetSocial.currentUser()
GetSocial.GetCurrentUser();
GetSocial.currentUser;
GetSocial.getCurrentUser();
GetSocialSDK.GetSocial.getCurrentUser();

This method returns null if SDK is not initialized.

Get User By ID

Public user profile is represented by User class. Object is read-only and provide access to name, avatar url, list of identities and public properties. Check entity reference for Android, iOS for more details.

The easiest way to get an instance of User is by GetSocial User Id:

Communities.getUser(UserId.create("getsocial-id"), { user: User ->
    Log.d("Communities", "User: $user")
}, { error: GetSocialError ->
    Log.d("Communities", "Failed to get user: $error")
})
Communities.user(UserId.create(withId: "getsocial-id"), success: { user in
    // process user data
}, failure: { error in
    // Ooops. There was some error while getting other user details.
})
Communities.GetUser(UserId.Create("getsocial-id"),
    (user) => {
    // process user data
    },
    (error) => {
    // Ooops. There was some error while getting other user details.
    });
Communities.getUser(UserId.create('getsocial-id'))
    .then((result) => // process user data)
    .catchError((error) => // Ooops. There was some error while getting other user details. );
Communities.getUser(UserId.create('getsocial-id'))
    .then((result) => { } // process user data)
    , (error) => { }); // Ooops. There was some error while getting other user details. )
GetSocialSDK.Communities.getUser(GetSocialSDK.UserId.create('getsocial-id'))
    .then((result) => { } // process user data)
    , (error) => { }); // Ooops. There was some error while getting other user details. )

Also you can get multiple users by their ids:

Communities.getUsers(UserIdList.create("getsocial-id", "other-id"), { users: List<User> ->
    Log.d("Communities", "Users: $users")
}, { error: GetSocialError ->
    Log.d("Communities", "Failed to get users: $error")
})
Communities.users(UserIdList.create(["getsocial-id", "other-id"]), success: { users in
    // process users data
}, failure: { error in
    // Ooops. There was some error while getting other users details.
})
Communities.GetUsers(UserIdList.Create("user1", "user2"),
    (users) => {
    // process users data
    },
    (error) => {
    // Ooops. There was some error while getting other users details.
    });
Communities.getUsers(UserIdList.create(['user1', 'user2']))
    .then((result) => // process user data)
    .catchError((error) => // Ooops. There was some error while getting other user details. );
Communities.getUsersByIds(UserIdList.create(['user1', 'user2']))
    .then((result) => { }) // process user data
    .catch((error) => {}); // Ooops. There was some error while getting other user details.
GetSocialSDK.Communities.getUsersByIds(GetSocialSDK.UserIdList.create(['user1', 'user2']))
    .then((result) => { }) // process user data
    .catch((error) => {}); // Ooops. There was some error while getting other user details.

Find Users

You can find users by their display name and by username if you have added username identities for your users.

val query = UsersQuery.find("John")
val pagingQuery = PagingQuery(query)
Communities.getUsers(pagingQuery, { result: PagingResult<User> ->
    val users = result.entries
    Log.d("Communities", "Users with name John: $users")
}, { error: GetSocialError ->
    Log.d("Communities", "Failed to get users: $error")
})
let query = UsersQuery.find("John Doe")
query.limit = 10
let pagingQuery = UsersPagingQuery(query)
Communities.users(pagingQuery, success: { response in
    // Show list of users
}, failure: { error in
    // Error occured
})
var query = UsersQuery.Find("John Doe");
var pagingQuery = new PagingQuery<UsersQuery>(query);
Communities.GetUsers(pagingQuery,
    (result) => {
        // Show list of users
    }, failure: { error in
        // Error occured
    })
var query = UsersQuery.find('John Doe');
var pagingQuery = PagingQuery(query);
Communities.findUsers(pagingQuery)
    .then((result) {
        // Show list of users
    })
    .catchError((error) => print('Failed to find users, error: $error'));
const query = UsersQuery.find('John Doe');
const pagingQuery = new PagingQuery(query);
Communities.getUsers(pagingQuery)
    .then((result) => {
        // Show list of users
    }, (error) => {
        console.log('Failed to find users, error: ' + error.message);
    });
const query = GetSocialSDK.UsersQuery.find('John Doe');
GetSocialSDK.Communities.getUsers(new GetSocialSDK.PagingQuery(query))
    .then((result) => {
        // Show list of users
    }, (error) => {
        console.log('Failed to find users, error: ', error);
    });

Search

Searching for a user by name requires at least 3 characters.

Next Steps

Well-done! Your user is set up, see what to do next:

  • Connect your user with others using our Social Graph.
  • Post to global or custom news feeds and communicate with others with Activity Feed.

Give us your feedback! Was this article helpful?

😀 🙁