question

Kim Strasser avatar image
Kim Strasser asked

How can I get the entity key?

How can I use GetEntityToken in Xamarin?

PlayFabAuthenticationAPI.GetEntityToken(new GetEntityTokenRequest(),
(entityResult) =>
{
    var entityId = entityResult.Entity.Id;
    var entityType = entityResult.Entity.Type;
}, OnPlayFabError); // Define your own OnPlayFabError function to report errors

https://api.playfab.com/docs/tutorials/entities/getting-started-entities

entities
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

·
JayZuo avatar image
JayZuo answered

In Entities tutorial, it used Unity code for demonstrating. But in Xamarin, we will need to use PlayFab CSharpSDK not Unity SDK. The main difference is that they use different asynchronous pattern.

The Unity SDK uses a callback pattern. For each API call, you can always find a resultCallback and a errorCallback. Within these callbacks you can handle any logic you want.

The CSharpSDK uses async/await pattern. For each method, you can use keyword await to get the response of the API call. And then use .Error to get error, .Result to get result.

So in Xamarin, your code would like

var entityTokenResp = await PlayFabAuthenticationAPI.GetEntityTokenAsync(new PlayFab.AuthenticationModels.GetEntityTokenRequest());
if (entityTokenResp.Error == null)
{
    var entityId = entityTokenResp.Result.Entity.Id;
    var entityType = entityTokenResp.Result.Entity.Type;
}
else
{
    //Deal with error
}

If you are not familiar with async/await pattern, you can refer to https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/.

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.