Skip to content

Get and Find Users

Get Current User

It is not possible to obtain the instance of a current user object, but SDK provides methods to read and update user properties via static class:

```java tab=”Android(Java)”
GetSocial.User.getDisplayName();

```kotlin tab="Android(Kotlin)"
GetSocial.User.getDisplayName()

```objc tab=”iOS(Objective-C)”
[GetSocialUser displayName];

```swift tab="iOS(Swift)"
GetSocialUser.displayName

```c# tab=”Unity”
GetSocial.User.DisplayName;

```javascript tab="React Native"
GetSocialUser.getDisplayName().then((displayName) => {});

Get User By ID

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

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

```java tab=”Android(Java)”
GetSocial.getUserById(“GetSocial User Id”, new Callback() {
@Override
public void onSuccess(PublicUser publicUser) {
// process user data
}
@Override
public void onFailure(GetSocialException e) {
// Ooops. There was some exception while getting other user details.
}
});

```kotlin tab="Android(Kotlin)"
GetSocial.getUserById("GetSocial User Id", object : Callback<PublicUser> {
    override fun onSuccess(publicUser: PublicUser) {
        // process user data
    }

    override fun onFailure(exception: GetSocialException) {
        // Ooops. There was some exception while getting other user details.
    }
})

```objc tab=”iOS(Objective-C)”
[GetSocial userWithId:@”GetSocial User Id” success:^(GetSocialPublicUser * _Nonnull publicUser) {
// process user data
} failure:^(NSError * _Nonnull error) {
// Ooops. There was some error while getting other user details.
}];

```swift tab="iOS(Swift)"
GetSocial.user(withId: "GetSocial User Id", success: { publicUser in
    // process user data
}, failure: { error in
    // Ooops. There was some error while getting other user details.
})

```c# tab=”Unity”
GetSocial.GetUserById(“GetSocial User Id”,
user =>
{
// process user data
},
error =>
{
// Ooops. There was some exception while getting other user details.
});

```javascript tab="React Native"
GetSocial.getUserById('GetSocial User Id').then((publicUser) => {
    // process user data
}, (error) {
    // Ooops. There was some exception while getting other user details.
});

Also you can get users by their identities:

Find Users

You can find users by their display name:

```java tab=”Android(Java)”
UsersQuery query = UsersQuery.usersByDisplayName(“John Doe”).withLimit(10);
GetSocial.findUsers(query, new Callback>() {
@Override
public void onSuccess(List users) {
// Show list of users
}

1
2
3
4
@Override
public void onFailure(GetSocialException exception) {
    // Error occured
}

});
kotlin tab=”Android(Kotlin)”
val query = UsersQuery.usersByDisplayName(“John Doe”).withLimit(10)
GetSocial.findUsers(query, object : Callback>{
override fun onSuccess(users: List) {
// Show list of users
}

override fun onFailure(exception: GetSocialException) {
// Error occured
}
})
```

```objc tab=”iOS(Objective-C)”
GetSocialUsersQuery *usersQuery = [GetSocialUsersQuery usersByDisplayName:@”John Doe”];
[usersQuery setLimit:10];
[GetSocial findUsers:usersQuery
success:^(NSArray *users) {
// Show list of users
}
failure:^(NSError *error) {
// Error occured
}];

```swift tab="iOS(Swift)"
let usersQuery = GetSocialUsersQuery.users(byDisplayName: "John Doe")
usersQuery.setLimit(10)
GetSocial.findUsers(usersQuery, success: { users in
    // Show list of users
}, failure: { error in
    // Error occured
})

```c# tab=”Unity”
UsersQuery query = UsersQuery.UsersByDisplayName(“John Doe”).WithLimit(10);
GetSocial.FindUsers(query,
users =>
{
// Show list of users
},
error =>
{
// Error occured
});

```javascript tab="React Native"
const query = UsersQuery.usersByDisplayName('John Doe').withLimit(10);
GetSocial.findUsers(query).then((users) => {
    // Show list of users
}, (error) => {
    // Error occured
});

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?

😀 🙁