question

Canberk Soner avatar image
Canberk Soner asked

Entity token for Title

On Unity SDK, I'm trying to call PlayFabCloudScriptAPI.ExecuteEntityCloudScript in my game server, but I do not have the entity token.

How do I get the entity token for title?

How do I pass it to PlayFabCloudScriptAPI.ExecuteEntityCloudScript? I haven't seen a parameter for entity token there.

What I'm actually trying to do: I need the game server to call a cloudscript function that will run a custom logic on multiple players. PlayFabServerAPI.ExecuteCloudScript doesn't really fit this case because I think it calls the cloudscript function on behalf of a player. I can make sure the function isn't accessible by clients by passing a secret key, that's not the problem. The problem is it feels "hacky" to pass player ids as a parameter while calling it on behalf of a player.

Kinda confusing, hope my question is clear. No idea what I've missed here.

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

To get entity token for Title, you will need to use GetEntityToken method. And in Unity, it will like the following:

PlayFabAuthenticationAPI.GetEntityToken(new PlayFab.AuthenticationModels.GetEntityTokenRequest(),
    result =>
    {
        Debug.Log("You've got title entity token: " + result.EntityToken);
    },
    error => { Debug.LogError(error.GenerateErrorReport()); });

Please note that you will need to enable server API and set developer secret key so that this API can execute successfully.

And for your requirement, since it's in your game server, you can use any server API to do anything that a cloudscript function can do. So I think you can just bypass cloudscript function to achieve what you want.

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.

Canberk Soner avatar image Canberk Soner commented ·

Thanks for the help. I still don't understand how to pass the entity token to PlayFabCloudScriptAPI.ExecuteCloudScript, though.

As for your last comment, I've noticed that server api execution times are many times shorter when the call is made from cloudscript. That's why I'm using some cloudscript functions for game logic that requires multiple server api calls.

0 Likes 0 ·
JayZuo avatar image JayZuo ♦ Canberk Soner commented ·

You do not need to pass the entity token. Since you are using Unity SDK, EntityToken is handled internally by the SDK, so you can ignore that. However, I didn't use PlayFabCloudScriptAPI.ExecuteCloudScript in server before. If your cloudscript function is not related to entities, I'd think you should still use PlayFabServerAPI.ExecuteCloudScript.

0 Likes 0 ·
Canberk Soner avatar image Canberk Soner JayZuo ♦ commented ·

I see. I guess I'll continue with that approach. I think CloudScript wasn't intended to be used this way for actions involving multiple players, but the execution time difference is really too much, so I'm batching the game server related cloudscript functions (until I hit the 25 api request limit, at least).

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.