Manage User Profile¶
Display Name¶
```java tab=”Android(Java)”
// Check current username
String name = GetSocial.User.getDisplayName();
// To update display name
GetSocial.User.setDisplayName(newDisplayName, completionCallback);
```kotlin tab="Android(Kotlin)"
// Check current username
val name = GetSocial.User.getDisplayName()
// To update display name
GetSocial.User.setDisplayName(newDisplayName, object: CompletionCallback {})
```objc tab=”iOS(Objective-C)”
// Check current username
NSString *name = [GetSocialUser displayName];
// To update display name
[GetSocialUser setDisplayName:newDisplayName success:success failure:failure];
```swift tab="iOS(Swift)"
// Check current username
let name: String = GetSocialUser.displayName
// To update display name
GetSocialUser.setDisplayName(newDisplayName, success: success, failure:failure)
```c# tab=”Unity”
// Check current username
var name = GetSocial.User.DisplayName;
// To update display name
GetSocial.User.SetDisplayName(newDisplayName, OnSuccess, OnError);
```javascript tab="React Native"
// 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.
```java tab=”Android(Java)”
// 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);
```kotlin tab="Android(Kotlin)"
// 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 {})
```objc tab=”iOS(Objective-C)”
// 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];
```swift tab="iOS(Swift)"
// 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)
```c# tab=”Unity”
// 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);
```javascript tab="React Native"
// 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.
- You can set in total 10 public and 100 private properties.
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:
```java tab=”Android(Java)”
GetSocial.User.setPrivateProperty(key, value, new CompletionCallback() {
@Override
public void onSuccess() {
Log.d(TAG, “Successfully set a private property”);
}
1 2 3 4 |
|
});
kotlin tab=”Android(Kotlin)”
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}”)
}
})
```
```objc tab=”iOS(Objective-C)”
[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);
}];
```swift tab="iOS(Swift)"
GetSocialUser.setPrivatePropertyValue(value, forKey: key, success: {
print("Successfully set a private property")
}, failure: { error in
print("Failed to set a private property, error: \(aDescription)")
})
```c# tab=”Unity”
GetSocial.User.SetPrivateProperty(key, value,
() =>
{
Debug.Log(“Successfully set private property”);
},
error =>
{
Debug.Log(“Failed to set private property, error:” + error);
});
```javascript tab="React Native"
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:
```java tab=”Android(Java)”
boolean hasPrivateProperty = GetSocial.User.hasPrivateProperty(key);
```kotlin tab="Android(Kotlin)"
val hasPrivateProperty = GetSocial.User.hasPrivateProperty(key)
```objc tab=”iOS(Objective-C)”
BOOL hasPrivateProperty = [GetSocialUser hasPrivatePropertyForKey:key];
```swift tab="iOS(Swift)"
let hasPrivateProperty: Bool = GetSocialUser.hasPrivateProperty(forKey: key)
```c# tab=”Unity”
bool hasPrivateProperty = GetSocial.User.HasPrivateProperty(key);
```javascript tab="React Native"
GetSocialUser.hasPrivateProperty(key).then((hasKey) => {});
You can get the current property value:
```java tab=”Android(Java)”
String currentValue = GetSocial.User.getPrivateProperty(key);
```kotlin tab="Android(Kotlin)"
val currentValue = GetSocial.User.getPrivateProperty(key)
```objc tab=”iOS(Objective-C)”
NSString *currentValue = [GetSocialUser privatePropertyValueForKey:key];
```swift tab="iOS(Swift)"
let currentValue = GetSocialUser.privatePropertyValue(forKey: key)
```c# tab=”Unity”
string currentValue = GetSocial.User.GetPrivateProperty(key);
```javascript tab="React Native"
GetSocialUser.getPrivateProperty(key).then((value) => {});
If you’re not interesting in keeping property for a user, remove it:
```java tab=”Android(Java)”
GetSocial.User.removePrivateProperty(key, new CompletionCallback() {
@Override
public void onSuccess() {
Log.d(TAG, “Property was successfully removed”);
}
1 2 3 4 |
|
});
kotlin tab=”Android(Kotlin)”
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}”)
}
})
```
```objc tab=”iOS(Objective-C)”
[GetSocialUser removePrivatePropertyForKey:key success:success failure:failure];
```swift tab="iOS(Swift)"
GetSocialUser.removePrivateProperty(forKey: key, success: success, failure: failure)
```c# tab=”Unity”
GetSocial.User.RemovePrivateProperty(key,
() =>
{
Debug.Log(“Successfully removed private property”);
},
error =>
{
Debug.Log(“Failed to remove private property, error:” + error);
});
```javascript tab="React Native"
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:
```java tab=”Android(Java)”
Map
```kotlin tab="Android(Kotlin)"
val userProperties = GetSocial.User.getAllPrivateProperties()
```objc tab=”iOS(Objective-C)”
NSDictionary
```swift tab="iOS(Swift)"
let userProperties = GetSocialUser.allPrivateProperties()
```c# tab=”Unity”
Dictionary
```javascript tab="React Native"
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:
```java tab=”Android(Java)”
String value = user.getPublicProperty(key);
```kotlin tab="Android(Kotlin)"
val value = user.getPublicProperty(key)
```objc tab=”iOS(Objective-C)”
NSString *value = [user publicPropertyForKey:key];
```swift tab="iOS(Swift)"
let value = user.publicPropertyValue(forKey: key)
```c# tab=”Unity”
string value = user.GetPublicProperty(key);
```javascript tab="React Native"
GetSocialUser.getPublicProperty(key).then((value) => {});
Or, you can check does user have a property:
```java tab=”Android(Java)”
boolean hasProperty = user.hasPublicProperty(key);
```kotlin tab="Android(Kotlin)"
val hasProperty = user.hasPublicProperty(key)
```objc tab=”iOS(Objective-C)”
BOOL hasProperty = [user hasPublicPropertyForKey:key];
```swift tab="iOS(Swift)"
let hasProperty: Bool = user.hasPublicProperty(forKey: key)
```c# tab=”Unity”
bool hasProperty = user.HasPublicProperty(key);
```javascript tab="React Native"
GetSocialUser.hasPublicProperty(key).then((hasKey) => {});
You can get all properties as unmodifiable copy of origin map:
```java tab=”Android(Java)”
Map
```kotlin tab="Android(Kotlin)"
val userProperties = user.getAllPublicProperties()
```objc tab=”iOS(Objective-C)”
NSDictionary
```swift tab="iOS(Swift)"
let userProperties = user.allPublicProperties()
```c# tab=”Unity”
Dictionary
```javascript tab="React Native"
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:
```java tab=”Android(Java)”
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”);
}
1 2 3 4 |
|
});
kotlin tab=”Android(Kotlin)”
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}”)
}
})
```
```objc tab=”iOS(Objective-C)”
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];
```swift tab="iOS(Swift)"
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)
```c# tab=”Unity”
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: