Manage User Profile

Display Name

1
2
3
4
5
// Check current username
String name = GetSocial.User.getDisplayName();

// To update display name
GetSocial.User.setDisplayName(newDisplayName, completionCallback);
1
2
3
4
5
// Check current username
val name = GetSocial.User.getDisplayName()

// To update display name
GetSocial.User.setDisplayName(newDisplayName, object: CompletionCallback {})
1
2
3
4
5
// Check current username
NSString *name = [GetSocialUser displayName];

// To update display name
[GetSocialUser setDisplayName:newDisplayName success:success failure:failure];
1
2
3
4
5
// Check current username
let name: String = GetSocialUser.displayName

// To update display name
GetSocialUser.setDisplayName(newDisplayName, success: success, failure:failure)
1
2
3
4
5
// Check current username
var name = GetSocial.User.DisplayName;

// To update display name
GetSocial.User.SetDisplayName(newDisplayName, OnSuccess, OnError);
1
2
3
4
5
// Check current username
GetSocialUser.getDisplayName().then((displayName) => {});

// To update display name
GetSocialUser.setDisplayName(newDisplayName).then(success, error);

Avatar

You can set avatar URL or directly an image which will be stored on GetSocial backend and used as avatar.

1
2
3
4
5
6
7
8
9
// Check current avatar
String avatarUrl = GetSocial.User.getAvatarUrl();

// To update avatar with URL
GetSocial.User.setAvatarUrl(newAvatarUrl, completionCallback);

// To update avatar with Image
Bitmap avatar = ... ; // get avatar image
GetSocial.User.setAvatar(avatar, completionCallback);
1
2
3
4
5
6
7
8
9
// Check current avatar
val avatarUrl = GetSocial.User.getAvatarUrl()

// To update avatar with URL
GetSocial.User.setAvatarUrl(newAvatarUrl, object: CompletionCallback {})

// To update avatar with Image
val avatar : Bitmap = ...
GetSocial.User.setAvatar(avatar, object: CompletionCallback {})
1
2
3
4
5
6
7
8
9
// Check current avatar
NSString *avatarUrl = [GetSocialUser avatarUrl];

// To update avatar with URL
[GetSocialUser setAvatarUrl:avatarUrl success:success failure:failure];

// To update avatar with Image
UIImage *avatar = ... ; // get avatar image
GetSocialUser setAvatar:avatar success:success failure:failure];
1
2
3
4
5
6
7
8
9
// Check current avatar
let avatarUrl: String = GetSocialUser.avatarUrl

// To update avatar with URL
GetSocialUser.setAvatarUrl(newAvatarUrl, success: success, failure:failure)

// To update avatar with Image
let avatar: UIImage = ... ; // get avatar image
GetSocialUser.setAvatar(avatar, success: success, failure:failure)
1
2
3
4
5
6
7
8
9
// Check current avatar
var avatarUrl = GetSocial.User.AvatarUrl;

// To update avatar with URL
GetSocial.User.SetAvatarUrl(newAvatarUrl, onSuccess, onFailure);

// To update avatar with Image
Texture2D avatar = ... ; // get avatar image
GetSocial.User.SetAvatar(avatar, completionCallback);
1
2
3
4
5
// Check current avatar
GetSocialUser.getAvatarUrl().then((avatarUrl) => {});

// To update avatar with URL
GetSocialUser.setAvatarUrl(newAvatarUrl).then(success, error);

Recommended size is 300x300 px, bigger images will be automatically downscaled.

User Properties

Custom properties are string to string map of any information your want to store.

There’re some limitations about properties:

  • Max key length is 32 symbols.
  • Max value length is 1024 symbols.
  • Min value length is 1 symbol, you can not set an empty property, it will just remove a current value if it exists.

There are Public and Private properties. Private properties are accessible only by current user, Public can be accessed by other users with methods from PublicUser object.

Private Properties

To set a private property:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
GetSocial.User.setPrivateProperty(key, value, new CompletionCallback() {
    @Override
    public void onSuccess() {
        Log.d(TAG, "Successfully set a private property");
    }

    @Override
    public void onFailure(GetSocialException exception) {
        Log.d(TAG, "Failed to set a private property, error: " + exception);
    }
});
1
2
3
4
5
6
7
8
9
GetSocial.User.setPrivateProperty(key, value, object: CompletionCallback{
    override fun onSuccess() {
        println("Successfully set a private property")
    }

    override fun onFailure(exception: GetSocialException) {
        println("Failed to set a private property, error: ${exception.message}")
    }
})
1
2
3
4
5
6
7
8
[GetSocialUser setPrivatePropertyValue:value
                                forKey:key
                               success:^() {
                                   NSLog(@"Successfully set a private property");
                               }
                               failure:^(NSError *error) {
                                   NSLog(@"Failed to set a private property, error: %@", error.description);
                               }];
1
2
3
4
5
GetSocialUser.setPrivatePropertyValue(value, forKey: key, success: {
    print("Successfully set a private property")
}, failure: { error in
    print("Failed to set a private property, error: \(aDescription)")
})
1
2
3
4
5
6
7
8
9
GetSocial.User.SetPrivateProperty(key, value,
    () =>
    {
        Debug.Log("Successfully set private property");
    },
    error =>
    {
        Debug.Log("Failed to set private property, error:" + error);
    });
1
2
3
4
5
GetSocialUser.setPrivateProperty(key, value).then(() => {
    console.log('Successfully set private property');
}, (error) => {
    console.log('Failed to set private property, error:' + error);
});

In case if user already had a value for a current key, it will be overridden. You can prevent it with checking if property already exists:

1
boolean hasPrivateProperty = GetSocial.User.hasPrivateProperty(key);
1
val hasPrivateProperty = GetSocial.User.hasPrivateProperty(key)
1
BOOL hasPrivateProperty = [GetSocialUser hasPrivatePropertyForKey:key];
1
let hasPrivateProperty: Bool = GetSocialUser.hasPrivateProperty(forKey: key)
1
bool hasPrivateProperty = GetSocial.User.HasPrivateProperty(key);
1
GetSocialUser.hasPrivateProperty(key).then((hasKey) => {});

You can get the current property value:

1
String currentValue = GetSocial.User.getPrivateProperty(key);
1
val currentValue = GetSocial.User.getPrivateProperty(key)
1
NSString *currentValue = [GetSocialUser privatePropertyValueForKey:key];
1
let currentValue = GetSocialUser.privatePropertyValue(forKey: key)
1
string currentValue = GetSocial.User.GetPrivateProperty(key);
1
GetSocialUser.getPrivateProperty(key).then((value) => {});

If you’re not interesting in keeping property for a user, remove it:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
GetSocial.User.removePrivateProperty(key, new CompletionCallback() {
    @Override
    public void onSuccess() {
        Log.d(TAG, "Property was successfully removed");
    }

    @Override
    public void onFailure(GetSocialException error) {
        Log.d(TAG, "Failed to remove a property, error: " + error);
    }
});
1
2
3
4
5
6
7
8
9
GetSocial.User.removePrivateProperty(key, object: CompletionCallback{
    override fun onSuccess() {
        println("Property was successfully removed")
    }

    override fun onFailure(exception: GetSocialException) {
        println("Failed to remove a property, error: ${exception.message}")
    }
})
1
[GetSocialUser removePrivatePropertyForKey:key success:success failure:failure];
1
GetSocialUser.removePrivateProperty(forKey: key, success: success, failure: failure)
1
2
3
4
5
6
7
8
9
GetSocial.User.RemovePrivateProperty(key, value,
    () =>
    {
        Debug.Log("Successfully removed private property");
    },
    error =>
    {
        Debug.Log("Failed to remove private property, error:" + error);
    });
1
2
3
4
5
GetSocialUser.removePrivateProperty(key).then(() => {
    console.log('Successfully removed private property');
}, (error) => {
    console.log('Failed to remove private property, error:' + error);
});

You can get all properties as unmodifiable copy of origin map:

1
Map<String, String> userProperties = GetSocial.User.getAllPrivateProperties();
1
val userProperties = GetSocial.User.getAllPrivateProperties()
1
NSDictionary<NSString *, NSString *> *userProperties = [GetSocialUser allPrivateProperties];
1
let userProperties = GetSocialUser.allPrivateProperties()
1
Dictionary<string, string> userProperties = GetSocial.User.AllPrivateProperties;
1
GetSocialUser.allPrivateProperties().then((properties) => {});

Note

You can not modify properties with this map. Also, changes in user properties won’t affect your copy, so you need to refresh it after any user changes. To have up-to-date information, we suggest to use GetSocial SDK methods.

Public Properties

You have similar methods to work with public properties.

In addition to this, Public properties are visible for other users, so if you have some PublicUser entity user, you can get his public properties:

1
String value = user.getPublicProperty(key);
1
val value = user.getPublicProperty(key)
1
NSString *value = [user publicPropertyForKey:key];
1
let value = user.publicPropertyValue(forKey: key)
1
string value = user.GetPublicProperty(key);
1
GetSocialUser.getPublicProperty(key).then((value) => {});

Or, you can check does user have a property:

1
boolean hasProperty = user.hasPublicProperty(key);
1
val hasProperty = user.hasPublicProperty(key)
1
BOOL hasProperty = [user hasPublicPropertyForKey:key];
1
let hasProperty: Bool = user.hasPublicProperty(forKey: key)
1
bool hasProperty = user.HasPublicProperty(key);
1
GetSocialUser.hasPublicProperty(key).then((hasKey) => {});

You can get all properties as unmodifiable copy of origin map:

1
Map<String, String> userProperties = user.getAllPublicProperties();
1
val userProperties = user.getAllPublicProperties()
1
NSDictionary<NSString *, NSString *> *userProperties = [user allPublicProperties];
1
let userProperties = user.allPublicProperties()
1
Dictionary<string, string> userProperties = GetSocial.User.AllPublicProperties;
1
GetSocialUser.allPublicProperties().then((properties) => {});

Note

You can not modify properties with this map. Also, changes in user properties won’t affect your copy, so you need to refresh it after any user changes. To have up-to-date information, we suggest to use GetSocial SDK methods.

Batch Properties Update

If you want to perform multiple updates of user data, you can do it with UserUpdate class. It allows you update few user properties(custom and not) in one request:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
UserUpdate batchUpdate = UserUpdate.createBuilder()
        .updateAvatarUrl(newAvatarUrl)
        .updateDisplayName(newDisplayName)
        .setPublicProperty(publicProperty1, newPublicValue)
        .removePublicProperty(publicProperty2)
        .setPrivateProperty(privateProperty1, newPrivateValue)
        .removePrivateProperty(privateProperty2)
        .build();

GetSocial.User.setUserDetails(batchUpdate, new CompletionCallback() {
    @Override
    public void onSuccess() {
        Log.d(TAG, "User details were successfully updated");
    }

    @Override
    public void onFailure(GetSocialException exception) {
        Log.d(TAG, "Failed to update user details, error: " + exception);
    }
});
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
val batchUpdate = UserUpdate.createBuilder()
    .updateAvatarUrl(newAvatarUrl)
    .updateDisplayName(newDisplayName)
    .setPublicProperty(publicProperty1, newPublicValue)
    .removePublicProperty(publicProperty2)
    .setPrivateProperty(privateProperty1, newPrivateValue)
    .removePrivateProperty(privateProperty2)
    .build()

GetSocial.User.setUserDetails(batchUpdate, object: CompletionCallback{
    override fun onSuccess() {
        println("User details were successfully updated")
    }

    override fun onFailure(exception: GetSocialException) {
        println("Failed to update user details, error: ${exception.message}")
    }
})
1
2
3
4
5
6
7
8
9
GetSocialUserUpdate batchUpdate = [GetSocialUserUpdate new];
batchUpdate.avatarUrl = newAvatarUrl;
batchUpdate.displayName = newDisplayName;
[batchUpdate setPublicPropertyValue:newPublicValue forKey:publicProperty1];
[batchUpdate removePublicPropertyForKey:publicProperty2];
[batchUpdate setPrivatePropertyValue:privateProperty1 forKey:newPrivateValue];
[batchUpdate removePrivatePropertyForKey:privateProperty2];

[GetSocialUser updateDetails:batchUpdate success:success failure:failure];
1
2
3
4
5
6
7
8
9
var batchUpdate = GetSocialUserUpdate()
batchUpdate.avatarUrl = newAvatarUrl
batchUpdate.displayName = newDisplayName
batchUpdate.setPublicPropertyValue(newPublicValue, forKey: publicProperty1)
batchUpdate.removePublicProperty(forKey: publicProperty2)
batchUpdate.setPrivatePropertyValue(privateProperty1, forKey: newPrivateValue)
batchUpdate.removePrivateProperty(forKey: privateProperty2)

GetSocialUser.updateDetails(batchUpdate, success: success, failure: failure)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
UserUpdate batchUpdate = UserUpdate.CreateBuilder()
    .UpdateAvatarUrl(newAvatarUrl)
    .UpdateDisplayName(newDisplayName)
    .SetPublicProperty(publicProperty1, newPublicValue)
    .RemovePublicProperty(publicProperty2)
    .SetPrivateProperty(privateProperty1, newPrivateValue)
    .RemovePrivateProperty(privateProperty2)
    .Build();

GetSocial.User.SetUserDetails(batchUpdate,
    () =>
    {
        Debug.Log("Successfully updated user details");
    },
    error =>
    {
        Debug.Log("Failed to update user details, error:" + error);
    });

Next Steps

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

Give us your feedback! Was this article helpful?

😀 🙁