question

Hans Weber avatar image
Hans Weber asked

[SOLVED] Cloudscript GetUserReadData, what am I missing?

Hello,

I am trying to add a function using UserReadOnlyData and while following the documentation it does not seem to want to work in Visual Studio.

My Code:

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using PlayFab;
using PlayFab.Samples;
using PlayFab.ServerModels;

[...]            



var UpdateUserTimeRequest = PlayFabServerAPI.UpdateUserReadOnlyData(new UpdateUserDataRequest() 
            {
                PlayFabId = context.CallerEntityProfile.Lineage.MasterPlayerAccountId,              // Way to get PlayfabID
                Data = new Dictionary<string, string>() 
                {
                    {"LastLoginTime", TimeResult.ToString()}
                },
                Permission = UserDataPermission.Public
            },
            result => Debug.Log("Set read-only user data successful"),
            error => 
            {
                Debug.Log("Got error updating read-only user data:");
                Debug.Log(error.GenerateErrorReport());
            });   
            var UpdateUserTimeResult = serverApi.UpdateUserReadOnlyDataAsync(UpdateUserTimeRequest);

Thank you for your help.

EDIT: I understand, that I am probably missing some repository. Which one is it and where would I get it?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Gosen Gao avatar image
Gosen Gao answered

Since the code you post didn’t include the definition of serverApi, just in case, to call server api, you need to set Title Id and Developer Secret Key first.

var apiSettings = new PlayFab.PlayFabApiSettings()
{
    TitleId = Environment.GetEnvironmentVariable("PLAYFAB_TITLE_ID", EnvironmentVariableTarget.Process),
    DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY", EnvironmentVariableTarget.Process)
};
var serverApi = new PlayFabServerInstanceAPI(apiSettings);

The code you are using should be implemented with Unity SDK. If you want to call UpdateUserReadOnlyData API with C# SDK, you should define the request like below.

var request = new UpdateUserDataRequest{
    PlayFabId = context.CallerEntityProfile.Lineage.MasterPlayerAccountId,
    Data = new Dictionary<string,string>{
        {"Key", "Value"}
    },
    Permission = UserDataPermission.Public
};
var ret = await serverApi.UpdateUserReadOnlyDataAsync(request);
4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hans Weber avatar image Hans Weber commented ·

to 1. The part with the secret key I had already implemented.

to 2. So there is basically no "UpdateUserReadOnlyDataRequest", right?
If I want to post something to there I just have to use the "UpdateUserReadOnlyDataAsync", since they are both processing the same information, this just saves it to a different list. Do I understand that correctly?

0 Likes 0 ·
Gosen Gao avatar image Gosen Gao Hans Weber commented ·

Yes, there is no "UpdateUserReadOnlyDataRequest". And if you want to update date to Read Only Data with C# SDK, you should use "UpdateUserReadOnlyDataAsync", and you can refer to my code above.

1 Like 1 ·
Hans Weber avatar image Hans Weber Gosen Gao commented ·

Thank you, that solved my problem. Does it work the same way for internal data?

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.