Profile
Overview
AccelByte Cloud's Profile services allow players to display information about themselves such as their Name, Location, Date of Birth, and Photos. Beyond these basic attributes, you can also create your own attributes to customize the player profiles for your game. For example, you can add attributes that include a player's level or rank. When you add these attributes to the Profile service, that information will be displayed on each player's profile.
Custom Attributes
Custom Attributes can be implemented using the SDK. In the sample code below four custom attributes have been added: level, rank, equipped sword, and equipped shield. When this code is implemented, these attributes will appear in each player's profile.
{
"userId": "string",
"namespace": "string",
"firstName": "string",
"lastName": "string",
"avatarSmallUrl": "string",
"avatarUrl": "string",
"avatarLargeUrl": "string",
"status": "ACTIVE",
"language": "string",
"timeZone": "string",
"dateOfBirth": "2019-12-22",
"customAttributes": {
"level": "1",
"rank": "Grand Master",
"activeWeapon": "Copper Sword",
"activeShield": "Pot Lid"
}
}
Prerequisites
- Make sure you are authorized and have registered your clients.
Implement Profiles using the Client SDKs
Create a Player Profile
Use the following function to create a player profile.
- Unreal Engine
- Unity
FAccelByteModelsUserProfileCreateRequest ProfileCreateRequest;
ProfileCreateRequest.FirstName = FString("MyFirstName");
ProfileCreateRequest.LastName = FString("MyLastName");
ProfileCreateRequest.AvatarSmallUrl = FString("https://example.com/avatar-small.jpeg");
ProfileCreateRequest.AvatarLargeUrl = FString("https://example.com/avatar-large.jpeg");
ProfileCreateRequest.AvatarUrl = FString(“https://example.com/avatar.peg”);
ProfileCreateRequest.DateOfBirth = FString("1999-10-12");
ProfileCreateRequest.Language = FString("en");
ProfileCreateRequest.Timezone = FString("Etc/UTC");
FRegistry::UserProfile.CreateUserProfile(ProfileCreateRequest, THandler<FAccelByteModelsUserProfileInfo>::CreateLambda([](const FAccelByteModelsUserProfileInfo& Result)
{
// Do something if CreateUserProfile has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if CreateUserProfile has an error
UE_LOG(LogTemp, Log, TEXT("Error CreateUserProfile, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
CreateUserProfileRequest createRequest = new CreateUserProfileRequest
{
firstName = "MyFirstName",
lastName = "MyLastName",
avatarSmallUrl = "https://example.com/avatar-small.jpeg",
avatarLargeUrl = "https://example.com/avatar-large.jpeg",
avatarUrl = "https://example.com/avatarjpeg",
dateOfBirth = "1999-10-12",
language = "en",
timeZone = "Etc/UTC",
customAttributes = new Dictionary<string, object>
{
{ "Level", 50 },
{ "Weapon", 25 },
{ "Armor", 20 }
}
};
AccelBytePlugin.GetUserProfiles().CreateUserProfile(createRequest, result =>
{
if (result.IsError)
{
// Do something if CreateUserProfile has an error
Debug.Log($"Error CreateUserProfile, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if CreateUserProfile has been successful
}
});
Retrieve a Player Profile
You can retrieve a player profile using the following function. This function will retrieve the player's personal information, such as First Name, Last Name, Language, etc.
- Unreal Engine
- Unity
FRegistry::UserProfile.GetUserProfile(THandler<FAccelByteModelsUserProfileInfo>::CreateLambda([](const FAccelByteModelsUserProfileInfo& Result)
{
// Do something if GetUserProfile has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetUserProfile has an error
UE_LOG(LogTemp, Log, TEXT("Error GetUserProfile, Error Code %d Error Message %s"), ErrorCode, *ErrorMessage);
}));
AccelBytePlugin.GetUserProfiles().GetUserProfile(result =>
{
if (result.IsError)
{
// Do something if GetUserProfile has an error
Debug.Log($"Error GetUserProfile, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if GetUserProfile has been successful
}
});
Retrieve a Player's Public Profile
If you need to get a player's public profile, you can use the following function. The public profile is the profile that other players see when interacting in the game. When retrieving a player's public profile, you will receive the player's User ID, Namespace, Timezone, and Avatar URL.
- Unreal Engine
FString UserId = FString("SomeUserId");
FRegistry::UserProfile.GetPublicUserProfileInfo(UserId, THandler<FAccelByteModelsPublicUserProfileInfo>::CreateLambda([](const FAccelByteModelsPublicUserProfileInfo& Result)
{
// Do something if GetPublicUserProfileInfo has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetPublicUserProfileInfo has an error
UE_LOG(LogTemp, Log, TEXT("Error GetPublicUserProfileInfo, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
Update a Player Profile
Use the following function to update a player profile.
- Unreal Engine
- Unity
FAccelByteModelsUserProfileUpdateRequest ProfileUpdateRequest;
ProfileUpdateRequest.FirstName = FString("MyNewFirstName");
ProfileUpdateRequest.LastName = FString("MyNewLastName");
ProfileUpdateRequest.AvatarSmallUrl = FString("https://example.com/avatar-small-new.jpeg");
ProfileUpdateRequest.AvatarLargeUrl = FString("https://example.com/avatar-large-new.jpeg");
ProfileUpdateRequest.AvatarUrl = FString("https://example.com/avatar-new.jpeg");
ProfileUpdateRequest.DateOfBirth = FString("2000-11-13");
ProfileUpdateRequest.Language = FString("en");
ProfileUpdateRequest.Timezone = FString("Etc/UTC");
FRegistry::UserProfile.UpdateUserProfile(ProfileUpdateRequest, THandler<FAccelByteModelsUserProfileInfo>::CreateLambda([](const FAccelByteModelsUserProfileInfo& Result)
{
// Do something if UpdateUserProfile has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if UpdateUserProfile has an error
UE_LOG(LogTemp, Log, TEXT("Error UpdateUserProfile, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
UpdateUserProfileRequest updateRequest = new UpdateUserProfileRequest
{
firstName = "MyNewFirstName",
lastName = "MyNewLastName",
avatarSmallUrl = "https://example.com/avatar-small-new.jpeg",
avatarLargeUrl = "https://example.com/avatar-large-new.jpeg",
avatarUrl = "https://example.com/avatar-new.jpeg",
dateOfBirth = "1999-10-12",
language = "en",
timeZone = "Etc/UTC",
customAttributes = new Dictionary<string, object>
{
{ "Level", 65 },
{ "Weapon", 30 },
{ "Armor", 30 }
}
};
AccelBytePlugin.GetUserProfiles().UpdateUserProfile(updateRequest, result =>
{
if (result.IsError)
{
// Do something if UpdateUserProfile has an error
Debug.Log($"Error UpdateUserProfile, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if UpdateUserProfile has been successful
}
});
Update Custom Attributes
The following function can be used to update a specific custom attribute field.
- Unreal Engine
- Unity
TSharedPtr<FJsonObject> CustomAttributes = MakeShareable(new FJsonObject);
CustomAttributes->SetNumberField("Level", 50);
CustomAttributes->SetNumberField("Armor", 25);
CustomAttributes->SetNumberField("Weapon", 20);
FRegistry::UserProfile.UpdateCustomAttributes(*CustomAttributes, THandler<FJsonObject>::CreateLambda([](const FJsonObject& Result)
{
// Do something if UpdateCustomAttributes has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString ErrorMessage)
{
// Do something if UpdateCustomAttributes has an error
UE_LOG(LogTemp, Log, TEXT("Error UpdateCustomAttributes, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
Dictionary<string, object> updates = new Dictionary<string, object>
{
{ "Level", 75 },
{ "Armor", 50 },
{ "Weapon", 25 }
};
AccelBytePlugin.GetUserProfiles().UpdateCustomAttributes(updates, result =>
{
if (result.IsError)
{
// Do something if UpdateCustomAttributes has an error
Debug.Log($"Error UpdateCustomAttributes, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if UpdateCustomAttributes has been successful
}
});
Retrieve Custom Attributes
You can retrieve a player profile with its custom attributes using the following function.
- Unreal Engine
- Unity
FRegistry::UserProfile.GetCustomAttributes(THandler<FJsonObject>::CreateLambda([](const FJsonObject& Result)
{
// Do something if GetCustomAttributes has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetCustomAttributes has an error
UE_LOG(LogTemp, Log, TEXT("Error GetCustomAttributes, Error Code: %d, ErrorMessage: %s"), ErrorCode, *ErrorMessage);
}));
AccelBytePlugin.GetUserProfiles().GetCustomAttributes(result =>
{
if (result.IsError)
{
// Do something if GetCustomAttributes has an error
Debug.Log($"Errpr GetCustomAttributes, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if GetCustomAttributes has been succesful
}
});
Retrieve Public Custom Attributes
You can retrieve a public player profile with custom attributes using the following function and specifying the user ID.
- Unreal Engine
FString UserId = FString("SomeUserId");
FRegistry::UserProfile.GetPublicCustomAttributes(UserId, THandler<FJsonObject>::CreateLambda([](const FJsonObject& Result)
{
// Do something if GetPublicCustomAttributes has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetPublicCustomAttributes has an error
UE_LOG(LogTemp, Log, TEXT("Error GetPublicCustomAttributes, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
Connect Custom Services to Profiles using the Server SDKs
SDK Initialization
Before using the Cloud Basic service (which includes the Profile service) from the SDK, you will need to initialize your server-side SDK to ensure you are authorized and able to perform create, read, update, and delete actions.
Golang SDK Initialization
Before using the Basic service from the Golang SDK, you will need to initialize the SDK by following the steps below:
Create your OAuth Client and assign the necessary permissions to access the Basic service.
Initialize the Basic service using the following function:
- Golang
userProfileService := &basic.UserProfileService{
Client: factory.NewBasicClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
Once completed, you can use the Golang SDK to create, read, update, or delete the Basic service from your serverless app.
Python SDK Initialization
Before using the Basic service from the Python SDK, you will need to initialize the SDK by following the steps below:
Create your OAuth Client and assign the necessary permissions to access the Basic service.
Once completed, you can use the Python SDK to create, read, update, or delete the Basic service from your serverless app.
.NET (C#) SDK Initialization
Before using the Basic service, you will need to set some permissions. Use the following .NET namespaces:
using AccelByte.Sdk.Api.Basic.Model;
using AccelByte.Sdk.Api.Basic.Operation;
using AccelByte.Sdk.Api.Basic.Wrapper;
Java SDK Initialization
Before using the Basic service, you will need to set some permissions. Initialize the UserProfile wrapper from the Basic service using the following code:
UserProfile wProfile = new UserProfile(sdk);
Once completed, you can use the SDK to create, read, update, or delete player profiles.
Create a Player Profile
Use the following function to create a player profile.
- Golang
- Python
- C#
- Java
userProfileService := &basic.UserProfileService{
Client: factory.NewBasicClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
from accelbyte_py_sdk.api.basic import create_my_profile
from accelbyte_py_sdk.api.basic.models import UserProfilePrivateCreate
result, error = create_my_profile(
body=UserProfilePrivateCreate.create(
first_name="<your-first-name>",
last_name="<your-last-name>"
)
)
if error:
print(error)
UserProfile wProfile = new UserProfile(sdk);
UserProfilePrivateCreate createProfile = new UserProfilePrivateCreate()
{
FirstName = "My First Name",
LastName = "My Last Name",
DateOfBirth = DateTime.ParseExact("2000-01-01", "yyyy-MM-dd", CultureInfo.InvariantCulture),
Language = "en"
};
UserProfilePrivateInfo? cInfo = wProfile.CreateMyProfile(
CreateMyProfile.Builder
.SetBody(createProfile)
.Build(sdk.Namespace));
UserProfilePrivateCreate createProfile = UserProfilePrivateCreate.builder()
.firstName(profileFirstName)
.lastName(profileLastName)
.dateOfBirth(profileDateOfBirth.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))
.language(profileLanguage)
.build();
UserProfilePrivateInfo cInfo = wProfile.createMyProfile(CreateMyProfile.builder()
.namespace(namespace)
.body(createProfile)
.build());
Delete a Player Profile
Use the following function to delete a player profile:
- Golang
- Python
- C#
- Java
err := userProfileService.DeleteUserProfile(input)
if err != nil {
return err
}
return nil
from accelbyte_py_sdk.api.basic import delete_user_profile
result, error = delete_user_profile(
user_id="<your-user-id>"
)
if error:
print(error)
UserProfile wProfile = new UserProfile(sdk);
UserProfilePrivateInfo? delResp = wProfile.DeleteUserProfile(DeleteUserProfile.Builder
.Build(sdk.Namespace, userId));
Assert.IsNotNull(delResp);
UserProfilePrivateInfo delResp = wProfile.deleteUserProfile(DeleteUserProfile.builder()
.namespace(namespace)
.userId(userId)
.build());
Retrieve a Player Profile
Use the following function to retrieve a public profile:
- Golang
- Python
- C#
- Java
ok, err := userProfileService.PublicGetUserProfileInfo(input)
if err != nil {
logrus.Error(err)
return err
}
return nil
from accelbyte_py_sdk.api.basic import public_get_user_profile_info
result, error = public_get_user_profile_info(
user_id="<your-user-id>"
)
if error:
print(error)
UserProfile wProfile = new UserProfile(sdk);
UserProfilePrivateInfo? ownResp = wProfile.GetMyProfileInfo(GetMyProfileInfo.Builder
.Build(sdk.Namespace));
UserProfileInfo userProfile = wProfile.publicGetUserProfileInfo(PublicGetUserProfileInfo.builder()
.namespace(namespace)
.userId(userId)
.build());
Update a Player Profile
Use the following function to update a player profile:
- Golang
- Python
- C#
- Java
ok, err := userProfileService.PublicUpdateUserProfile(input)
if err != nil {
logrus.Error(err)
return err
}
return nil
from accelbyte_py_sdk.api.basic import public_update_user_profile
from accelbyte_py_sdk.api.basic.models import UserProfileUpdate
result, error = public_update_user_profile(
user_id="<your-user-id>",
body=UserProfileUpdate.create(
first_name="<your-first-name>",
last_name="<your-last-name>"
)
)
if error:
print(error)
UserProfile wProfile = new UserProfile(sdk);
UserProfilePrivateUpdate updateProfile = new UserProfilePrivateUpdate()
{
TimeZone = "Asia/Jakarta"
};
UserProfilePrivateInfo? updResp = wProfile.UpdateMyProfile(UpdateMyProfile.Builder
.SetBody(updateProfile)
.Build(sdk.Namespace));
UserProfileUpdate upd = UserProfileUpdate.builder()
.timeZone(profileTimeZone)
.build();
wProfile.updateUserProfile( PublicUpdateUserProfile.builder()
.namespace(namespace)
.userId(userId)
.body(upd)
.build());
Related Concepts
- Learn how to manage player Statistics within your game.
- Golang test case files
- Python test case files
- .NET (C#) test case files
- Java test case files