question

Muhammad Roshaan Tariq avatar image
Muhammad Roshaan Tariq asked

Set Profile Language fails at Entity Auth

Hi,

I want to implement SetProfileLanguage Request in my game to allow users to change their languages. According to this document I need the Entity Key which I pass along with it but it still gives an error (Please check screenshot for Log/Error)


Also my player is already logged in so I'm not sure why it's saying of unauthorized access

apisAccount Management
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

Citrus Yan avatar image
Citrus Yan answered

The error message “This API method does not allow anonymous callers” in your case generally means that the entity token of the player’s entity is missing. I don’t know the details of your code, however, it’s possible that the entity token is erased somewhere in your code. You can call PlayFabSettings.staticPlayer.IsEntityLoggedIn() to see whether the current player’s entity is logged in before calling the SetProfileLanguage API. I did a simple test to set the profile language for a logged-in player and it worked properly, here is code you may find helpful:

using UnityEngine;
using PlayFab;
using PlayFab.ProfilesModels;
using PlayFab.ClientModels;
using EntityKey = PlayFab.ProfilesModels.EntityKey;


public class TestSetProfileLanguage : MonoBehaviour
{
    void Start()
    {
        Login("custom id of a player");
    }


    public void Login(string customId)
    {
        PlayFabClientAPI.LoginWithCustomID(
            new LoginWithCustomIDRequest()
            {
                CustomId = customId,
            },
            (loginResult) =>
            {
                Debug.Log("entity logged in: " + PlayFabSettings.staticPlayer.IsEntityLoggedIn());
                SetProfileName("en", PlayFabSettings.staticPlayer.EntityId, PlayFabSettings.staticPlayer.EntityType);
            },
            (error) =>
            {
                Debug.LogError(error.ErrorMessage);
            }
            );
    }
    public void SetProfileName(string language, string entityId, string entityType)
    {
        PlayFabProfilesAPI.SetProfileLanguage(
            new SetProfileLanguageRequest()
            {
                Language = language,
                Entity = new EntityKey()
                {
                    Id = entityId,
                    Type = entityType
                }
            },
            (result) =>
            {
                Debug.Log(result.ToJson());
            },
            (error) =>
            {
                Debug.LogError(error.ErrorMessage);
            }
            );
    }
}

What this code does is:

1.Log in a player using LoginWithCustomId.

2.Set the player’s profile language using SetProfileLanguage.

Moreover, warnings can also provide much valuable information, could you please turn that on in your Unity console and see what it says? And it would be helpful if you can provide your code for us to investigate.

2 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.

Muhammad Roshaan Tariq avatar image Muhammad Roshaan Tariq commented ·

@Citrus Yan Thanks it worked. I think the EntityID and Type was wrong in my case because I just changed it to "PlayfabSettings.staticPlayer.EntityID and Type" and it worked.

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Muhammad Roshaan Tariq commented ·

Glad it helped.

0 Likes 0 ·