ゲームクライアントからバイナリレコードにプレイヤーデータを保存する
注釈:本資料はAI技術を用いて翻訳されています。
概要
AccelByte Gaming Services (AGS) のCloud Saveサービスを使用すると、プレイヤーデータをバイナリ形式で保存できます。保存されたデータは特定のプレイヤーに紐付けられます。画像やオーディオファイルは、プレイヤーバイナリレコードに通常保存されるデータの一般的な例です。
このガイドでは、バイナリレコードを使用してプレイヤーデータを保存、取得、およびゲームのユースケースに応じて変更する方法を学びます。
前提条件
以下へのアクセスが必要です。
- AGS Admin Portal
- 必要な権限を持つ AGS Unreal、Unity、または Extend SDK
- Client ID
- Client Secret
- AGS Cloud Save API ドキュメント
ゲームクライアントからバイナリレコードにプレイヤーデータを保存する
プレイヤーデータをバイナリレコードに保存するには、次の順序で以下の手順に従います。
プレイヤーバイナリレコードを作成する
このプロセスでは、後でバイナリファイルをアップロードするために使用される生成済みの事前署名URLを取得します。作成したいレコードに追加の読み取り検証を設定することもできます。
- レコード所有者のみがデータにアクセスできるようにする
- すべてのプレイヤーがレコードデータにアクセスできるようにする
追加の読み取り検証の詳細については、Cloud Saveの概要を参照してください。
リクエストを作成するには、次の関数を使用します。
- Unreal
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python Extend SDK
FApiClientPtr ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
FString Key = "userInformation";
FString FileType = "bin"; // Valid file types are JPEG, JPG, PNG, BMP, GIF, MP3, WebP, and BIN
bool bIsPublic = true; // Set to true if you want the binary to be public
ApiClient->BinaryCloudSave.SaveUserBinaryRecord(Key
, FileType
, bIsPublic
, FVoidHandler::CreateLambda([]()
{
// What to do if SaveUserBinaryRecord is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if SaveUserBinaryRecord fails
}));
var binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string key = "userInformation";
string fileType = "bin"; // Valid file types are JPEG, JPG, PNG, BMP, GIF, MP3, WebP, and BIN
bool isPublic = true; // Set to true if you want the binary to be public
binaryCloudSave.SaveUserBinaryRecord(key, fileType, result =>
{
if (result.IsError)
{
// Your logic to handle errors in SaveUserBinaryRecord
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after SaveUserBinaryRecord is successful
}, isPublic);
string userId = "<user-id>";
string key = "someKey";
var response = sdk.Cloudsave.PublicPlayerBinaryRecord.PostPlayerBinaryRecordV1Op
.Execute(new ModelsPublicPlayerBinaryRecordCreate()
{
Key = key,
FileType = "bin",
IsPublic = true
}, sdk.Namespace, userId);
if (response != null)
{
string presignedUrlToUpload = response.Url!;
}
publicPlayerBinaryRecordService := &cloudsave.PublicPlayerBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
key := "someKey"
fileType := "bin"
isPublic := true
body := &cloudsaveclientmodels.ModelsPublicPlayerBinaryRecordCreate{
Key: &key,
FileType: &fileType,
IsPublic: isPublic,
}
namespace := "mygame"
userId := "myuserid"
input := &public_player_binary_record.PostPlayerBinaryRecordV1Params{
Body: body,
Namespace: namespace,
UserID: userId,
}
result, err := publicPlayerBinaryRecordService.PostPlayerBinaryRecordV1Short(input)
PublicPlayerBinaryRecord publicPlayerBinaryRecordWrapper = new PublicPlayerBinaryRecord(sdk);
String userId = "<user-id>";
String key = "someKey";
ModelsUploadBinaryRecordResponse response;
try {
ModelsPublicPlayerBinaryRecordCreate reqBody = ModelsPublicPlayerBinaryRecordCreate.builder()
.key(key)
.fileType("bin")
.isPublic(true)
.build();
response = publicPlayerBinaryRecordWrapper.postPlayerBinaryRecordV1(PostPlayerBinaryRecordV1.builder()
.namespace("<namespace>")
.userId(userId)
.body(reqBody)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
if (response == null) {
// Null response from server
} else {
String presignedUrlToUpload = response.getUrl();
}
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
result, error = cloudsave_service.post_player_binary_record_v1(
body=cloudsave_models.ModelsPublicPlayerBinaryRecordCreate()
.with_file_type("bin")
.with_key("userInformation")
.with_is_public(True),
user_id="********************************",
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)
プレイヤーバイナリレコードファイルをアップロードする
ユーザーバイナリレコードを作成した後、データをアップロードできます。必要なパラメータは、プレイヤーバイナリレコードを作成するセクションのコールバックから提供されます。次の関数を使用してデータをアップロードできます。
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python Extend SDK
byte[] yourUserDataToUpload; // Your user binary data
string url; // Retrieved via callback on successful SaveUserBinaryRecord (Value.BinaryInfo.Url)
AccelByteNetUtilities.UploadBinaryTo(binaryInfo.Url, yourUserDataToUpload, result =>
{
if (result.IsError)
{
// Your logic to handle errors in UploadBinaryTo
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after UploadBinaryTo is successful
});
string presignedUrlToUpload = "<url>"; //from PostPlayerBinaryRecordV1Op
byte[] dataToUpload = new byte[] { 10, 30, 40, 50, 60, 70, 80 };
var isSuccess = sdk.UploadBinaryData(presignedUrlToUpload, dataToUpload, "application/octet-stream");
if (isSuccess)
{
// Do something if upload succeeds
}
presignedURL := "PresignedUrlToUpload"
filePath := "FilePath"
resp, err := utils.UploadBinaryFile(presignedURL, token, filePath)
if err != nil {
// Do something if an error occurs
}
String presignedUrlToUpload = "<url>"; //from PostPlayerBinaryRecordV1Op
byte[] dataToUpload = new byte[] { 10, 30, 40, 50, 60, 70, 80 };
final boolean isSuccess = sdk.uploadBinaryData(presignedUrlToUpload, dataToUpload, "application/octet-stream");
if (isSuccess)
{
// Do something if upload succeeds
}
from accelbyte_py_sdk.core import get_http_client
# url = ...
# data_upload = ...
response = get_http_client().upload_binary_data(
url=url,
data=data_upload,
headers={
"Content-Type": "application/octet-stream",
}
)
変更をコミットする
バイナリファイルがアップロードされたら、変更をコミットして新しいファイルの場所が更新されるようにします。次の関数を使用します。
- Unreal
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python Extend SDK
FApiClientPtr ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
FString Key = "userInformation";
FString ContentType = "presignUrlContentType";
FString FileLocation = "presignUrlFileLocation";
ApiClient->BinaryCloudSave.UpdateUserBinaryRecordFile(Key
, ContentType
, FileLocation
, THandler<FAccelByteModelsUserBinaryRecord>::CreateLambda([](FAccelByteModelsUserBinaryRecord Result)
{
// What to do if UpdateUserBinaryRecordFile is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if UpdateUserBinaryRecordFile fails
}));
var binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string key = "userInformation";
string contentType; //Retrieved via callback on successful SaveUserBinaryRecord (Value.BinaryInfo.ContentType)
string fileLocation; //Retrieved via callback on successful SaveUserBinaryRecord (Value.BinaryInfo.FileLocation)
binaryCloudSave.UpdateUserBinaryRecordFile(key, contentType, fileLocation, result =>
{
if (result.IsError)
{
// Your logic to handle errors in UpdateUserBinaryRecordFile
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after UpdateUserBinaryRecordFile is successful
});
string userId = "<user-id>";
string key = "someKey";
string presignedUrlToUpload = "<url>";
var response = sdk.Cloudsave.PublicPlayerBinaryRecord.PutPlayerBinaryRecordV1Op
.Execute(new ModelsBinaryRecordRequest()
{
ContentType = "application/octet-stream",
FileLocation = presignedUrlToUpload
}, key, sdk.Namespace, userId);
if (response != null)
{
// Do something when successful
}
publicPlayerBinaryRecordService := &cloudsave.PublicPlayerBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
contentType := "application/octet-stream"
fileLocation := "presignedUrlToUpload"
body := &cloudsaveclientmodels.ModelsBinaryRecordRequest {
ContentType: &contentType,
FileLocation: &fileLocation,
}
key := "someKey"
namespace := "mygame"
userId := "myuserid"
input := &public_player_binary_record.PutPlayerBinaryRecordV1Params{
Body: body,
Key: key,
Namespace: namespace,
UserID: userId,
}
result, err := publicPlayerBinaryRecordService.PutPlayerBinaryRecordV1Short(input)
PublicPlayerBinaryRecord publicPlayerBinaryRecordWrapper = new PublicPlayerBinaryRecord(sdk);
String userId = "<user-id>";
String key = "someKey";
String presignedUrlToUpload = "<url>";
ModelsPlayerBinaryRecordResponse response;
try {
ModelsBinaryRecordRequest reqBody = ModelsBinaryRecordRequest.builder()
.contentType("application/octet-stream")
.fileLocation(presignedUrlToUpload)
.build();
response = publicPlayerBinaryRecordWrapper.putPlayerBinaryRecordV1(PutPlayerBinaryRecordV1.builder()
.namespace("<namespace>")
.userId(userId)
.key(key)
.body(reqBody)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
if (response == null) {
// Null response from server
} else {
// Do something when successful
}
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
# file_location = ... # from 'result.file_location' from 'post_player_binary_record_v1'
# content_type = ... # from 'result.content_type' from 'post_player_binary_record_v1'
result, error = cloudsave_service.put_player_binary_record_v1(
body=cloudsave_models.ModelsBinaryRecordRequest()
.with_content_type(content_type)
.with_file_location(file_location),
key="userInformation",
user_id="********************************",
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)
ゲームクライアントからプレイヤーバイナリレコードデータを取得する
レコード所有者に基づいて、2 種類のプレイヤーレコードを取得できます。
- 自分のプレイヤーバイナリレコード
- 他のユーザーの公開バイナリレコード
プレイヤーのバイナリレコードデータを取得する
単一取得
次の関数を使用して、キーでプレイヤー自身の特定のバイナリレコードデータを取得します。
- Unreal
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python Extend SDK
FApiClientPtr ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
FString Key = "userInformation";
ApiClient->BinaryCloudSave.GetCurrentUserBinaryRecord(Key
, THandler<FAccelByteModelsUserBinaryRecord>::CreateLambda([](FAccelByteModelsUserBinaryRecord Result)
{
// What to do if GetCurrentUserBinaryRecord is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if GetCurrentUserBinaryRecord fails
}));
var binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string key = "userInformation";
binaryCloudSave.GetCurrentUserBinaryRecord(key, result =>
{
if (callback.IsError)
{
// Your logic to handle errors in GetCurrentUserBinaryRecord
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after GetCurrentUserBinaryRecord is successful
});
string userId = "<user-id>";
string key = "someKey";
var response = sdk.Cloudsave.PublicPlayerBinaryRecord.GetPlayerBinaryRecordV1Op
.Execute(key, sdk.Namespace, userId);
if (response != null)
{
// Do something when successful
}
publicPlayerBinaryRecordService := &cloudsave.PublicPlayerBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
key := "someKey"
namespace := "mygame"
userId := "myuserid"
input := &public_player_binary_record.GetPlayerBinaryRecordV1Params{
Key: key,
Namespace: namespace,
UserID: userId,
}
result, err := publicPlayerBinaryRecordService.GetPlayerBinaryRecordV1Short(input)
PublicPlayerBinaryRecord publicPlayerBinaryRecordWrapper = new PublicPlayerBinaryRecord(sdk);
String userId = "<user-id>";
String key = "someKey";
ModelsPlayerBinaryRecordResponse response;
try {
response = publicPlayerBinaryRecordWrapper.getPlayerBinaryRecordV1(GetPlayerBinaryRecordV1.builder()
.key(key)
.namespace(namespace)
.userId(userId)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
if (response == null) {
// Null response from server
} else {
// Do something when successful
}
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
result, error = cloudsave_service.get_player_binary_record_v1(
key="userInformation",
user_id="********************************",
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)
一括取得
次の関数を使用して、プレイヤーが所有するバイナリレコードのリストを取得します。
- Unreal
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python Extend SDK
FApiClientPtr ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
TArray<FString> Keys = {"userInformation1", "userInformation2"};
ApiClient->BinaryCloudSave.BulkGetCurrentUserBinaryRecords(Keys
, THandler<FAccelByteModelsListUserBinaryRecords>::CreateLambda([](FAccelByteModelsListUserBinaryRecords Result)
{
// What to do if BulkGetCurrentUserBinaryRecords is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if BulkGetCurrentUserBinaryRecords fails
}));
var binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string[] keys = new string[] {
"userInformation1",
"userInformation2"
};
binaryCloudSave.BulkGetCurrentUserBinaryRecords(keys, result =>
{
if (callback.IsError)
{
// Your logic to handle errors in BulkGetCurrentUserBinaryRecords
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after BulkGetCurrentUserBinaryRecords is successful
});
string[] keys = new[] { "key1", "key2" };
var response = sdk.Cloudsave.PublicPlayerBinaryRecord.BulkGetMyBinaryRecordV1Op
.Execute(new ModelsBulkGetPlayerRecordsRequest()
{
Keys = new List<string>(keys)
}, sdk.Namespace);
if (response != null)
{
// Do something when successful
}
publicPlayerBinaryRecordService := &cloudsave.PublicPlayerBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
body := &cloudsaveclientmodels.ModelsBulkGetPlayerRecordsRequest {
Keys: string[]{"key1", "key2"},
}
namespace := "mygame"
input := &public_player_binary_record.BulkGetMyBinaryRecordV1Params{
Body: body,
Namespace: namespace,
}
result, err := publicPlayerBinaryRecordService.BulkGetMyBinaryRecordV1Short(input)
PublicPlayerBinaryRecord publicPlayerBinaryRecordWrapper = new PublicPlayerBinaryRecord(sdk);
List<String> keys = Arrays.asList("key1", "key2");
ModelsBulkGetPlayerBinaryRecordResponse response;
try {
ModelsBulkGetPlayerRecordsRequest reqBody = ModelsBulkGetPlayerRecordsRequest.builder()
.keys(keys)
.build();
response = publicPlayerBinaryRecordWrapper.bulkGetMyBinaryRecordV1(BulkGetMyBinaryRecordV1.builder()
.namespace("<namespace>")
.body(reqBody)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
if (response == null) {
// Null response from server
} else {
// Do something when successful
}
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
result, error = cloudsave_service.bulk_get_my_binary_record_v1(
body=cloudsave_models.ModelsBulkGetPlayerRecordsRequest().with_keys(["userInformation1", "userInformation2"]),
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)
他のユーザーの公開バイナリレコードデータを取得する
単一取得
次の関数を使用して、キーで特定のプレイヤーの公開バイナリレコードデータを取得します。
- Unreal
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python Extend SDK
FApiClientPtr ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
FString Key = "userInformation";
FString UserId = "OtherPlayerUserId";
ApiClient->BinaryCloudSave.GetPublicUserBinaryRecord(Key
, UserId
, THandler<FAccelByteModelsUserBinaryRecord>::CreateLambda([](FAccelByteModelsUserBinaryRecord Result)
{
// What to do if GetPublicUserBinaryRecord is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if GetPublicUserBinaryRecord fails
}));
var binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string key = "userInformation";
string userId = "otherPlayerUserId";
binaryCloudSave.GetPublicUserBinaryRecord(key, userId, result =>
{
if (result.IsError)
{
// Your logic to handle errors in GetPublicUserBinaryRecord
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after GetPublicUserBinaryRecord is successful
});
string userId = "<user-id>";
string key = "someKey";
var response = sdk.Cloudsave.PublicPlayerBinaryRecord.GetPlayerPublicBinaryRecordsV1Op
.Execute(key, sdk.Namespace, userId);
if (response != null)
{
// Do something when successful
}
publicPlayerBinaryRecordService := &cloudsave.PublicPlayerBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
key := "someKey"
namespace := "mygame"
userId := "myuserid"
input := &public_player_binary_record.GetPlayerPublicBinaryRecordsV1Params{
Key: key,
Namespace: namespace,
UserID: userId,
}
result, err := publicPlayerBinaryRecordService.GetPlayerPublicBinaryRecordsV1Short(input)
PublicPlayerBinaryRecord publicPlayerBinaryRecordWrapper = new PublicPlayerBinaryRecord(sdk);
String userId = "<user-id>";
String key = "someKey";
ModelsPlayerBinaryRecordResponse response;
try {
response = publicPlayerBinaryRecordWrapper.getPlayerPublicBinaryRecordsV1(GetPlayerPublicBinaryRecordsV1.builder()
.namespace("<namespace>")
.userId(userId)
.key(key)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
if (response == null) {
// Null response from server
} else {
// Do something when successful
}
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
result, error = cloudsave_service.get_player_public_binary_records_v1(
key="userInformation",
user_id="********************************",
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)
一括取得
次の関数を使用して、他のプレイヤーが所有する公開バイナリレコードのリストを取得します。
- Unreal
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python Extend SDK
FApiClientPtr ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
TArray<FString> Keys = {"userInformation1", "userInformation2"};
FString UserId = "OtherPlayerUserId";
ApiClient->BinaryCloudSave.BulkGetPublicUserBinaryRecords(Keys
, UserId
, THandler<FAccelByteModelsListUserBinaryRecords>::CreateLambda([](FAccelByteModelsListUserBinaryRecords Result)
{
// What to do if BulkGetPublicUserBinaryRecords is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if BulkGetPublicUserBinaryRecords fails
}));
var binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string[] keys = new string[] {
"userInformation1",
"userInformation2"
};
string userId = "otherPlayerUserId";
binaryCloudSave.BulkGetPublicUserBinaryRecords(keys, userId, result =>
{
if (result.IsError)
{
// Your logic to handle errors in BulkGetPublicUserBinaryRecords
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after BulkGetPublicUserBinaryRecords is successful
});
string userId = "<user-id>";
string[] keys = new[] { "key1", "key2" };
var response = sdk.Cloudsave.PublicPlayerBinaryRecord.BulkGetOtherPlayerPublicBinaryRecordsV1Op
.Execute(new ModelsBulkGetPlayerRecordsRequest()
{
Keys = new List<string>(keys)
}, sdk.Namespace, userId);
if (response != null)
{
// Do something when successful
}
publicPlayerBinaryRecordService := &cloudsave.PublicPlayerBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
body := &cloudsaveclientmodels.ModelsBulkGetPlayerRecordsRequest {
Keys: string[]{ "key1", "key2" },
}
namespace := "mygame"
userId := "myuserid"
input := &public_player_binary_record.BulkGetOtherPlayerPublicBinaryRecordsV1Params{
Body: body,
Namespace: namespace,
UserID: userId,
}
result, err := publicPlayerBinaryRecordService.BulkGetOtherPlayerPublicBinaryRecordsV1Short(input)
PublicPlayerBinaryRecord publicPlayerBinaryRecordWrapper = new PublicPlayerBinaryRecord(sdk);
String userId = "<user-id>";
List<String> keys = Arrays.asList("key1", "key2");
ModelsBulkGetPlayerBinaryRecordResponse response;
try {
ModelsBulkGetPlayerRecordsRequest reqBody = ModelsBulkGetPlayerRecordsRequest.builder()
.keys(keys)
.build();
response = publicPlayerBinaryRecordWrapper.bulkGetOtherPlayerPublicBinaryRecordsV1(BulkGetOtherPlayerPublicBinaryRecordsV1.builder()
.namespace("<namespace>")
.userId(userId)
.body(reqBody)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
if (response == null) {
// Null response from server
} else {
// Do something when successful
}
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
result, error = cloudsave_service.bulk_get_other_player_public_binary_records_v1(
body=ModelsBulkGetPlayerRecordsRequest().with_keys(["userInformation1", "userInformation2"]),
user_id="********************************",
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)
ゲームクライアントからプレイヤーバイナリレコードを変更する
プレイヤーバイナリレコードデータは、ゲームのユースケースに基づいて変更できます。プレイヤーバイナリレコードデータを変更する方法は 2 つあります。
- ゲームクライアント経由で変更する。プレイヤーが自分のプレイヤーバイナリレコードデータを変更できるようにする場合は、この方法を使用します。
- ゲームサーバー経由で変更する。ゲームサーバーのみがプレイヤーバイナリレコードデータを変更できるようにする場合は、この方法を使用します。
追加の書き込み検証の詳細については、Cloud Saveの概要を参照してください。
また、プレイヤーが更新したい情報を決定できるようにすることもできます。レコードメタデータまたはバイナリファイルです。
プレイヤーバイナリレコードメタデータを変更する
次の関数を使用して、レコードメタデータのみを変更します。
- Unreal
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python Extend SDK
FApiClientPtr ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
FString Key = "userInformation";
FString FileType = "bin"; // Valid file types are JPEG, JPG, PNG, BMP, GIF, MP3, WebP, and BIN
bool bIsPublic = true; // Set to true if you want the binary to be public
ApiClient->BinaryCloudSave.SaveUserBinaryRecord(Key
, FileType
, bIsPublic
, FVoidHandler::CreateLambda([]()
{
// What to do if SaveUserBinaryRecord is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if SaveUserBinaryRecord fails
}));
var binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string key = "userInformation";
bool isPublic = true; // Set to true if you want the binary to be public
binaryCloudSave.UpdateUserBinaryRecordMetadata(key, isPublic, result =>
{
if (result.IsError)
{
// Your logic to handle errors in UpdateUserBinaryRecordMetadata
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after UpdateUserBinaryRecordMetadata is successful
});
string userId = "<user-id>";
string key = "someKey";
var response = sdk.Cloudsave.PublicPlayerBinaryRecord.PutPlayerBinaryRecorMetadataV1Op
.Execute(new ModelsPlayerBinaryRecordMetadataPublicRequest()
{
IsPublic = true
}, key, sdk.Namespace, userId);
if (response != null)
{
// Do something when successful
}
publicPlayerBinaryRecordService := &cloudsave.PublicPlayerBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
body := &cloudsaveclientmodels.ModelsPlayerBinaryRecordMetadataPublicRequest {
IsPublic: true,
}
key := "someKey"
namespace := "mygame"
userId := "myuserid"
input := &public_player_binary_record.PutPlayerBinaryRecorMetadataV1Params{
Body: body,
Key: key,
Namespace: namespace,
UserID: userId,
}
result, err := publicPlayerBinaryRecordService.PutPlayerBinaryRecorMetadataV1Short(input)
PublicPlayerBinaryRecord publicPlayerBinaryRecordWrapper = new PublicPlayerBinaryRecord(sdk);
String userId = "<user-id>";
String key = "someKey";
ModelsPlayerBinaryRecordResponse response;
try {
ModelsPlayerBinaryRecordMetadataPublicRequest reqBody = ModelsPlayerBinaryRecordMetadataPublicRequest.builder()
.isPublic(true)
.build();
response = publicPlayerBinaryRecordWrapper.putPlayerBinaryRecorMetadataV1(PutPlayerBinaryRecorMetadataV1.builder()
.namespace("<namespace>")
.userId(userId)
.key(key)
.body(reqBody)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
if (response == null) {
// Null response from server
} else {
// Do something when successful
}
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
result, error = cloudsave_service.post_player_binary_record_v1(
body=cloudsave_models.ModelsPublicPlayerBinaryRecordCreate()
.with_file_type("bin")
.with_key("userInformation")
.with_is_public(True),
user_id="********************************",
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)
新しいプレイヤーバイナリレコードファイルをアップロードする
ゲームクライアントからプレイヤーバイナリレコードに新しいプレイヤーバイナリファイルをアップロードするには、次の順序で以下の手順に従います。
事前署名URLをリクエストする
ゲームクライアントで更新されたバイナリファイルをアップロードするには、事前署名URLが必要です。事前署名URLをリクエストするには、次の関数を使用します。
- Unreal
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python Extend SDK
FApiClientPtr ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
FString Key = "userInformation";
FString FileType = "bin"; // Valid file types are JPEG, JPG, PNG, BMP, GIF, MP3, WebP, and BIN
ApiClient->BinaryCloudSave.RequestUserBinaryRecordPresignedUrl(Key
, FileType
, THandler<FAccelByteModelsBinaryInfo>::CreateLambda([](FAccelByteModelsBinaryInfo Result)
{
// What to do if RequestUserBinaryRecordPresignedUrl is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if RequestUserBinaryRecordPresignedUrl fails
}));
var binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string key = "userInformation";
string fileType = "bin"; // Valid file types are JPEG, JPG, PNG, BMP, GIF, MP3, WebP, and BIN
binaryCloudSave.RequestUserBinaryRecordPresignedUrl(key, fileType, result =>
{
if (result.IsError)
{
// Your logic to handle errors in RequestUserBinaryRecordPresignedUrl
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after RequestUserBinaryRecordPresignedUrl is successful
});
string key = "someKey";
string userId = "<user-id>";
var response = sdk.Cloudsave.PublicPlayerBinaryRecord.PostPlayerBinaryPresignedURLV1Op
.Execute(new ModelsUploadBinaryRecordRequest()
{
FileType = "bin"
}, key, sdk.Namespace, userId);
if (response != null)
{
string presignedUrlToUpload = response.Url!;
}
publicPlayerBinaryRecordService := &cloudsave.PublicPlayerBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
key := "someKey"
fileType := "bin"
body := &cloudsaveclientmodels.ModelsUploadBinaryRecordRequest {
FileType: &fileType,
}
namespace := "namespace"
userId := "myuserid"
input := &public_player_binary_record.PostPlayerBinaryPresignedURLV1Params{
Body: body,
Key: key,
Namespace: namespace,
UserID: userId,
}
result, err := publicPlayerBinaryRecordService.PostPlayerBinaryPresignedURLV1Short(input)
PublicPlayerBinaryRecord publicPlayerBinaryRecordWrapper = new PublicPlayerBinaryRecord(sdk);
String key = "someKey";
String userId = "<user-id>";
ModelsUploadBinaryRecordResponse response;
try {
ModelsUploadBinaryRecordRequest reqBody = ModelsUploadBinaryRecordRequest.builder()
.fileType("bin")
.build();
response = publicPlayerBinaryRecordWrapper.postPlayerBinaryPresignedURLV1(PostPlayerBinaryPresignedURLV1.builder()
.namespace("<namespace>")
.userId(userId)
.key(key)
.body(reqBody)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
if (response == null) {
// Null response from server
} else {
String presignedUrlToUpload = response.getUrl();
}
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
result, error = cloudsave_service.post_player_binary_presigned_urlv1(
body=cloudsave_models.ModelsUploadBinaryRecordRequest()
.with_file_type("bin")
key="userInformation",
user_id="********************************",
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)
バイナリファイルをアップロードする
事前署名URLをリクエストするセクションから必要なパラメータを取得したら、希望するバイナリデータまたはファイルをアップロードします。次の関数を使用します。
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python Extend SDK
byte[] yourUserDataToUpload; // Your user binary data
string url; // Retrieved via callback on successful RequestUserBinaryRecordPresignedUrl (Value.Url)
AccelByteNetUtilities.UploadBinaryTo(binaryInfo.Url, yourUserDataToUpload, result =>
{
if (result.IsError)
{
// Your logic to handle errors in UploadBinaryTo
//...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after UploadBinaryTo is successful
});
string presignedUrlToUpload = "<url>"; //from PostPlayerBinaryPresignedURLV1Op
byte[] dataToUpload = new byte[] { 80, 30, 40, 50, 60, 70, 80 };
var isSuccess = sdk.UploadBinaryData(presignedUrlToUpload, dataToUpload, "application/octet-stream");
if (isSuccess)
{
// Do something if upload succeeds
}
presignedURL := "PresignedUrlToUpload"
filePath := "FilePath"
resp, err := utils.UploadBinaryFile(presignedURL, token, filePath)
if err != nil {
// Do something if an error occurs
}
String presignedUrlToUpload = "<url>"; //from PostPlayerBinaryPresignedURLV1
byte[] dataToUpload = new byte[] { 80, 30, 40, 50, 60, 70, 80 };
final boolean isSuccess = sdk.uploadBinaryData(presignedUrlToUpload, dataToUpload, "application/octet-stream");
if (isSuccess)
{
// Do something if upload succeeds
}
from accelbyte_py_sdk.core import get_http_client
# url = ... # from 'result.url' from 'post_player_binary_presigned_urlv1'
# data_upload = ...
response = get_http_client().upload_binary_data(
url=url,
data=data_upload,
headers={
"Content-Type": "application/octet-stream",
}
)
変更をコミットする
バイナリファイルがアップロードされたら、変更をコミットして新しいファイルの場所が更新されるようにします。次の関数を使用します。
- Unreal
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python Extend SDK
FApiClientPtr ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
FString Key = "userInformation";
// The following are taken from RequestUserBinaryRecordPresignedUrl's resulting FAccelByteModelsBinaryInfo
FString ContentType = RequestPresignedUrlResult.Content_Type;
FString FileLocation = RequestPresignedUrlResult.File_Location;
ApiClient->BinaryCloudSave.UpdateUserBinaryRecordFile(Key
, ContentType
, FileLocation
, THandler<FAccelByteModelsUserBinaryRecord>::CreateLambda([](FAccelByteModelsUserBinaryRecord Result)
{
// What to do if UpdateUserBinaryRecordFile is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if UpdateUserBinaryRecordFile fails
}));
var binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string key = "userInformation";
string contentType; //Retrieved via callback on successful RequestUserBinaryRecordPresignedUrl (Value.ContentType)
string fileLocation; //Retrieved via callback on successful RequestUserBinaryRecordPresignedUrl (Value.FileLocation)
binaryCloudSave.UpdateUserBinaryRecordFile(key, contentType, fileLocation, result =>
{
if (result.IsError)
{
// Your logic to handle errors in UpdateUserBinaryRecordFile
// ...
return;
}
// Your logic to run after UpdateUserBinaryRecordFile is successful
});
string userId = "<user-id>";
string key = "someKey";
string presignedUrlToUpload = "<url>";
var response = sdk.Cloudsave.PublicPlayerBinaryRecord.PutPlayerBinaryRecordV1Op
.Execute(new ModelsBinaryRecordRequest()
{
ContentType = "application/octet-stream",
FileLocation = presignedUrlToUpload
}, key, sdk.Namespace, userId);
if (response != null)
{
// Do something when successful
}
publicPlayerBinaryRecordService := &cloudsave.PublicPlayerBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
contentType := "application/octet-stream"
fileLocation := "presignedUrlToUpload"
body := &cloudsaveclientmodels.ModelsBinaryRecordRequest {
ContentType: &contentType,
FileLocation: &fileLocation,
}
key := "someKey"
namespace := "mygame"
userId := "myuserid"
input := &public_player_binary_record.PutPlayerBinaryRecordV1Params{
Body: body,
Key: key,
Namespace: namespace,
UserID: userId,
}
result, err := publicPlayerBinaryRecordService.PutPlayerBinaryRecordV1Short(input)
PublicPlayerBinaryRecord publicPlayerBinaryRecordWrapper = new PublicPlayerBinaryRecord(sdk);
String userId = "<user-id>";
String key = "someKey";
String presignedUrlToUpload = "<url>";
ModelsPlayerBinaryRecordResponse response;
try {
ModelsBinaryRecordRequest reqBody = ModelsBinaryRecordRequest.builder()
.contentType("application/octet-stream")
.fileLocation(presignedUrlToUpload)
.build();
response = publicPlayerBinaryRecordWrapper.putPlayerBinaryRecordV1(PutPlayerBinaryRecordV1.builder()
.namespace("<namespace>")
.userId(userId)
.key(key)
.body(reqBody)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
if (response == null) {
// Null response from server
} else {
// Do something when successful
}
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
# file_location = ... # from 'result.file_location' from 'post_player_binary_presigned_urlv1'
# content_type = ... # from 'result.content_type' from 'post_player_binary_presigned_urlv1'
result, error = cloudsave_service.put_player_binary_record_v1(
body=cloudsave_models.ModelsBinaryRecordRequest()
.with_content_type(content_type)
.with_file_location(file_location),
key="userInformation",
user_id="********************************",
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)
ゲームクライアントからプレイヤーバイナリレコードを削除する
プレイヤーが自分のプレイヤーバイナリレコードのみを削除できるようにすることができます。プレイヤーバイナリレコードを削除するには、次の関数を使用します。
- Unreal
- Unity
- C# Extend SDK
- Go Extend SDK
- Java Extend SDK
- Python Extend SDK
FApiClientPtr ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
FString Key = "userInformation";
ApiClient->BinaryCloudSave.DeleteUserBinaryRecord(Key
, FVoidHandler::CreateLambda([]()
{
// What to do if DeleteUserBinaryRecord is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// What to do if DeleteUserBinaryRecord fails
}));
var binaryCloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetBinaryCloudSave();
string key = "userInformation";
binaryCloudSave.DeleteUserBinaryRecord(key, result =>
{
if (result.IsError)
{
// Your logic to handle errors in DeleteUserBinaryRecord
// ...
Debug.Log(result.Error.Message);
return;
}
// Your logic to run after DeleteUserBinaryRecord is successful
});
string userId = "<user-id>";
string key = "someKey";
sdk.Cloudsave.PublicPlayerBinaryRecord.DeletePlayerBinaryRecordV1Op
.Execute(key, sdk.Namespace, userId);
publicPlayerBinaryRecordService := &cloudsave.PublicPlayerBinaryRecordService{
Client: factory.NewCloudsaveClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
key := "someKey"
namespace := "mygame"
userId := "myuserid"
input := &public_player_binary_record.DeletePlayerBinaryRecordV1Params{
Key: key,
Namespace: namespace,
UserID: userId,
}
err := publicPlayerBinaryRecordService.DeletePlayerBinaryRecordV1Short(input)
final PublicPlayerBinaryRecord publicPlayerBinaryRecordWrapper = new PublicPlayerBinaryRecord(sdk);
String userId = "<user-id>";
String key = "someKey";
try {
publicPlayerBinaryRecordWrapper.deletePlayerBinaryRecordV1(DeletePlayerBinaryRecordV1.builder()
.namespace("<namespace>")
.userId(userId)
.key(key)
.build());
} catch (Exception e) {
// Do something when failed
return;
}
import accelbyte_py_sdk.api.cloudsave as cloudsave_service
import accelbyte_py_sdk.api.cloudsave.models as cloudsave_models
result, error = cloudsave_service.delete_player_record_handler_v1(
key="userInformation",
user_id="********************************",
namespace=namespace, # optional, gets the value from the global instance if unspecified
sdk=sdk, # optional, gets the global instance if unspecified
)
if error:
exit(error)