question

tomassvedin avatar image
tomassvedin asked

Can't get DisplayName using GetPlayerProfileRequest

I'm trying to get the players DisplayName, I don't get any errors but the string is empty even tho I've set one from the Dashboard. What am I doing wrong here?

This is the code I'm using:

using UnityEngine;
using PlayFab.ClientModels;
using PlayFab;
using TMPro;


public class UserLogin : MonoBehaviour {


    [SerializeField] private TMP_InputField username;
    [SerializeField] private TMP_InputField password;


    public void LoginUser()
    {
        string uname = username.text;
        string pwd = password.text;


        var request = new LoginWithEmailAddressRequest
        {
            Email = uname,
            Password = pwd
        };


        PlayFabClientAPI.LoginWithEmailAddress(request, OnLoginSucess, OnFailure);
    }


    private void GetAccountInfo(string PID)
    {
        var request = new GetPlayerProfileRequest
        {
            PlayFabId = PID,
            ProfileConstraints = new PlayerProfileViewConstraints()
            {
                ShowDisplayName = true
            }
        };
        Debug.Log("PlayFabID: " + PID);
        PlayFabClientAPI.GetPlayerProfile(request, OnInfoSuccess, OnFailure);
    }


    void OnInfoSuccess(GetPlayerProfileResult result)
    {
        Debug.Log("Displayname: " + result.PlayerProfile.DisplayName);
    }


    private void OnLoginSucess(LoginResult result)
    {
        Debug.Log("You are logged in! " + result.PlayFabId.ToString());
        GetAccountInfo(result.PlayFabId);
    }




    private void OnFailure(PlayFabError error)
    {
        Debug.LogError("Something went wrong >>\n" + error.ErrorMessage);
    }


}


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

·
brendan avatar image
brendan answered

What is the Title ID for this test? Also, can you make sure the items you want to get back in the profile are selected in Settings->Client Profile Options?

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.