question

Mark Whitfield avatar image
Mark Whitfield asked

Return displayname in OnLoginSuccess callback?

public void LoginButtonPressed() {

	var request = new LoginWithEmailAddressRequest() {

		Email = loginUsernameInput.text,

		Password = loginPasswordInput.text,

		InfoRequestParameters = ????

	}

	PlayFabClientAPI.LoginWithEmailAddress(request, OnLoginSuccess, OnError);
}


private void OnLoginSuccess(LoginResult result) {
	string displayName = ???
}

I found this thread : https://community.playfab.com/questions/750/209139357-How-to-get-the-Display-Name-.html, but I don't fully understand the answer there.

I'm still not sure exactly what to type in the InfoRequestParameters of my request and in my OnLoginSuccess callback in order to get the displayname from that callback. Any advice appreciated. Thanks
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Mark Whitfield avatar image Mark Whitfield commented ·

Ok so I've got it to return the DisplayName, but realised thats just blank so actually I would like to get the username.

this is the code for getting it to return the displayname:

public void LoginButtonPressed() {

var request = new LoginWithEmailAddressRequest()
{
    Email = loginUsernameInput.text,
    Password = loginPasswordInput.text,
    InfoRequestParameters = new GetPlayerCombinedInfoRequestParams() {
        GetPlayerProfile = true,
        ProfileConstraints = new PlayerProfileViewConstraints() {
            ShowDisplayName = true
        }
    }
};
PlayFabClientAPI.LoginWithEmailAddress(request, OnLoginSuccess, OnError);

}
private void OnLoginSuccess(LoginResult result)
{
    playfabDisplayName = result.InfoResultPayload.PlayerProfile.DisplayName;
    Debug.Log("name " + playfabDisplayName);
}

What would I need to put to get the username back instead?

0 Likes 0 ·
Made Wang avatar image
Made Wang answered

Refer to Authentication - Login With Email Address - REST API (PlayFab Client) | Microsoft Docs and set the data flag that needs to be returned to true in InfoRequestParameters.

If you are using C# on Unity, refer to the following code.

public void LoginWithEmail()
    {
        PlayFabClientAPI.LoginWithEmailAddress(new LoginWithEmailAddressRequest
        {
            Email = email.text,
            Password = pwd.text,
            InfoRequestParameters = new GetPlayerCombinedInfoRequestParams
            {
                GetUserAccountInfo = true
            }
        },
        (result) =>
        {
            Debug.Log(result.InfoResultPayload.AccountInfo.Username);
        },
        (error) =>
        {
            Debug.LogError(error.GenerateErrorReport());
        });
    }

You can also use GetAccountInfo, refer to the code of @HapyGames.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Mark Whitfield avatar image Mark Whitfield commented ·

thanks that works

0 Likes 0 ·
hapygames avatar image
hapygames answered

Here you go, this Script might help you.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PlayFab;
using PlayFab.ClientModels;
using System;


public class GetAccountInfo : MonoBehaviour
{
    public static GetAccountInfo getAccountInfo;


    private void Awake()
    {
        getAccountInfo = this;
    }


    private void Start()
    {
        GetPlayerAccountInfo();
    }


    public void GetPlayerAccountInfo()
    {
        var request = new GetAccountInfoRequest();


        PlayFabClientAPI.GetAccountInfo(request, GetAccountInfoSuccess, GetAccountInfoError);
    }


    private void GetAccountInfoSuccess(GetAccountInfoResult result)
    {
        print("Recieved the AccountInformations");
        print(result.AccountInfo.Username);
    }


    private void GetAccountInfoError(PlayFabError error)
    {
        Debug.LogError(error.ErrorMessage);
    }
}


1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Mark Whitfield avatar image Mark Whitfield commented ·

thanks for your reply. i could do a separate call to get the account info, but i wanted to do it all in 1 call at the same time as logging in. the other answer provided does that.

0 Likes 0 ·

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.