question

dk-1 avatar image
dk-1 asked

How to get Title Objects from Azure CloudScript?

Can you provide c# example how to get Title Objects from Azure Cloud? How to get json with "Data" key? 6668-1.png

 var settings = new PlayFabApiSettings
         {
             TitleId = TITLE_ID,
             DeveloperSecretKey = DEVELOPER_SECRET_KEY
         };
         var authContext = new PlayFabAuthenticationContext
         {
             EntityToken = context.TitleAuthenticationContext.EntityToken
         };
            
         var getObjectRequest = new GetObjectsRequest
         {
             Entity = new EntityKey()
             {
                 Id = context.CallerEntityProfile.Entity.Id,
                 Type = context.CallerEntityProfile.Entity.Type
             }
         };
            
         var dataApi = new PlayFabDataInstanceAPI(settings, authContext);
    
         PlayFabResult<GetObjectsResponse>? getObjectsResponse = await dataApi.GetObjectsAsync(getObjectRequest);
            
         Dictionary<string, ObjectResult>? getObjectsResult = getObjectsResponse.Result.Objects;
CloudScript
1.png (152.5 KiB)
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

To get the Title Object, you have to call the GetObjects API with Title Entity Token and set the Entity parameter to Title Entity. The “context.CallerEntityProfile.Entity” is the title_player_account entity not Title entity. Here is the code example you may refer to.

 public static class TestFunction1
     {
         [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());
    
           var apiSettings =new PlayFab.PlayFabApiSettings()
           {
             TitleId=Environment.GetEnvironmentVariable("PLAYFAB_TITLE_ID",EnvironmentVariableTarget.Process),
             DeveloperSecretKey=Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY",EnvironmentVariableTarget.Process)
           };
    
           var titleContext=new PlayFabAuthenticationContext()
           {
             EntityToken=context.TitleAuthenticationContext.EntityToken,
             EntityId=Environment.GetEnvironmentVariable("PLAYFAB_TITLE_ID",EnvironmentVariableTarget.Process),
             EntityType="title"
           };
    
           log.LogDebug(context.CallerEntityProfile.Entity.Id+context.CallerEntityProfile.Entity.Type);
                
         var getObjectRequest = new GetObjectsRequest
          {
              Entity = new PlayFab.DataModels.EntityKey
              {
                  Id = "YourTitleId",
                  Type = "title"
              }
          };
                
          var dataApi = new PlayFabDataInstanceAPI(apiSettings, titleContext);
        
          PlayFabResult<GetObjectsResponse> getObjectsResponse = await dataApi.GetObjectsAsync(getObjectRequest);
    
          return getObjectsResponse;
    
          }
     }
10 |1200

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

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.