question

xigmasuji avatar image
xigmasuji asked

I get "master_player_account 'some number' not found in namespace 'some number' " when I use UpdateUserDataAsync to update data

I create an anonymous login from Unity, and I procure it's entity token and entity IDcall PlayFabAuthenticationContext in the Azure Function to get the PlayFabServerInstanceAPI and then use that to call the UpdateUserDataAsync.

          var api = new PlayFabServerInstanceAPI(
             new PlayFabApiSettings
             {
                     TitleId = context.TitleAuthenticationContext.Id,
                     DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY", EnvironmentVariableTarget.Process)
             },
             new PlayFabAuthenticationContext
             {
                 PlayFabId = context.CallerEntityProfile.Entity.Id,
                 EntityToken = context.TitleAuthenticationContext.EntityToken
             }
         );

Even in its request I have set

       PlayFab.ServerModels.UpdateUserDataRequest updateDataRequest = new PlayFab.ServerModels.UpdateUserDataRequest(){
             PlayFabId = context.CallerEntityProfile.Entity.Id,
             Permission = PlayFab.ServerModels.UserDataPermission.Public
         };

Yet when I call

PlayFabResult updateDataResult = await api.UpdateUserDataAsync(updateDataRequest);

This is what I get

"master_player_account 'some number' not found in namespace 'some number' "

Please help me understand what I am missing, thank you

Player Dataunity3dCloudScriptPlayStream
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

·
Xiao Zha avatar image
Xiao Zha answered

context.CallerEntityProfile.Entity.Id” is the title player account Id not the PlayFabId, you should use “context.CallerEntityProfile.Lineage.MasterPlayerAccountId” to get PlayFabId. Also, you can refer to Available Built-In Entity Types - PlayFab | Microsoft Learn to find more information about entity. And below is my working code, you can refer to:

 [FunctionName("Test")]
         public static async Task<dynamic> Run(
             [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null )] HttpRequest req,
             ILogger log)
         {
                
              var context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());
                
             log.LogInformation(context.CallerEntityProfile.Entity.Id);
    
             var api = new PlayFabServerInstanceAPI(
              new PlayFabApiSettings
              {
                      TitleId = context.TitleAuthenticationContext.Id,
                      DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY", EnvironmentVariableTarget.Process)
              },
              new PlayFabAuthenticationContext
              { 
                  EntityToken = context.TitleAuthenticationContext.EntityToken
              });
    
             PlayFab.ServerModels.UpdateUserDataRequest updateDataRequest = new PlayFab.ServerModels.UpdateUserDataRequest(){
              PlayFabId = context.CallerEntityProfile.Lineage.MasterPlayerAccountId,
              Permission = PlayFab.ServerModels.UserDataPermission.Public,
              Data=new Dictionary<string, string>{
                 {"Test","test"}}
          };
               
            var updateDataResult = await api.UpdateUserDataAsync(updateDataRequest);
             return new { message=updateDataResult.Result.DataVersion };         
                
         }
1 comment
10 |1200

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

xigmasuji avatar image xigmasuji commented ·

Thank you very much, understood and it works:))

0 Likes 0 ·

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.