Get and Find Users

Get Current User

To get an instance of current user:

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

This method returns null is 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:

1
2
3
4
5
Communities.getUser(UserId.create("getsocial-id"), { user: User ->
    Log.d("Communities", "User: $user")
}, { error: GetSocialError ->
    Log.d("Communities", "Failed to get user: $error")
})
1
2
3
4
5
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.
})
1
2
3
4
5
6
7
Communities.GetUser(UserId.Create("getsocial-id"),
    (user) => {
    // process user data
    },
    (error) => {
    // Ooops. There was some error while getting other user details.
    });
1
2
3
Communities.getUser(UserId.create('getsocial-id'))
    .then((result) => // process user data)
    .catchError((error) => // Ooops. There was some error while getting other user details. );
1
2
3
Communities.getUser(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:

1
2
3
4
5
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")
})
1
2
3
4
5
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.
})
1
2
3
4
5
6
7
Communities.GetUsers(UserIdList.Create("user1", "user2"),
    (users) => {
    // process users data
    },
    (error) => {
    // Ooops. There was some error while getting other users details.
    });
1
2
3
Communities.getUsers(UserIdList.create(['user1', 'user2']))
    .then((result) => // process user data)
    .catchError((error) => // Ooops. There was some error while getting other user details. );
1
2
3
Communities.getUsers(UserIdList.create(['user1', 'user2']))
    .then((result) => { } // process user data)
    .catchError((error) => {}); // Ooops. There was some error while getting other user details.

Find Users

You can find users by their display name:

1
2
3
4
5
6
7
8
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")
})
1
2
3
4
5
6
7
8
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
})
1
2
3
4
5
6
7
8
9
var query = UsersQuery.Find("John Doe");
var pagingQuery = new PagingQuery<UsersQuery>(query);
Communities.GetUsers(pagingQuery,
    (result) => {
    // Show list of users
    },
    (error) => {
    // Error occured
    });
1
2
3
4
5
6
7
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'));
1
2
3
4
5
6
7
8
const query = UsersQuery.find('John Doe');
const pagingQuery = new PagingQuery(query);
Communities.findUsers(pagingQuery)
    .then((result) => {
        // Show list of users
    }, (error) => {
        console.log('Failed to find users, error: ' + error.message);
    });

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?

😀 🙁