Advertisement
Guest User

Untitled

a guest
Oct 28th, 2022
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1.         [FunctionName("HelloWorld")]
  2.         public static async Task<dynamic> Run(
  3.             [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
  4.             ILogger log)
  5.         {
  6.             string bd =  await req.ReadAsStringAsync();
  7.             log.LogInformation($" req.Body: { bd}");
  8.             FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(bd);
  9.  
  10.                       //  log.LogInformation($"req body: {new StreamReader(httpRequest.Body).ReadToEnd()}");
  11.       //      var context2 = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());
  12.             var serverSettings = new PlayFab.PlayFabApiSettings()
  13.             {
  14.                 TitleId = Environment.GetEnvironmentVariable("PLAYFAB_TITLE_ID"),
  15.                 DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY")
  16.             };
  17.  
  18.             var titleAuthContext = new PlayFabAuthenticationContext();
  19.             //titleAuthContext.EntityToken = context.TitleAuthenticationContext.EntityToken;
  20.  
  21.             var s = new PlayFabEconomyInstanceAPI(serverSettings,titleAuthContext);
  22.  
  23.             var lootboxItemRef = new PlayFab.EconomyModels.InventoryItemReference
  24.             {
  25.                 Id = "45d5a69f-63eb-4fe9-bb17-3461526d6a61",
  26.                 StackId = "default"
  27.             };
  28.  
  29.             PlayFab.EconomyModels.EntityKey entity = new PlayFab.EconomyModels.EntityKey {
  30.                  Id = context.CallerEntityProfile.Entity.Id, Type = context.CallerEntityProfile.Entity.Type
  31.                  };
  32.  
  33.             var request = new AddInventoryItemsRequest(){
  34.                 Amount = 1,
  35.                 Entity = entity,
  36.                 Item = lootboxItemRef
  37.             };
  38.  
  39.             return await s.AddInventoryItemsAsync(request);
  40.  
  41.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement