question

pmattei0 avatar image
pmattei0 asked

How to get the displayname to use it on unity ?

Hello, I m currently searching somes info about the display name.

I have seen that there is a tuto only for this part, there :

https://api.playfab.com/docs/tutorials/landing-players/getting-player-profiles

But I lack information, I do not understand where is stored the display name after the " GetPlayerProfile " call.

I have already used the which is shown in the tuto, but how can I use the result to associate it with a text in Unity for example ?

My thanks.

Account Managementdata
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

·
1807605288 avatar image
1807605288 answered

Here's a quick guide to learn how to read our API documentation. Almost all new customers will start with the Client API documentation:
Client API Documentation

Find your API method, in this case, GetPlayerProfile:
GetPlayerProfile

Scroll down to the "Response Details", and, in this case, note there's only 1 sub-object, which is the "PlayerProfile" itself. Click the PlayerProfileModel link to see more details about that object type. PlayerProfile is the property name, and PlayerProfileModel is the type-name in this case.
PlayerProfileModel

You will find your answer in that last link, as the string DisplayName is one of the PlayerProfileModel fields. You can see lots of other information in the Profile if it's returned for your request/title. Your title settings in game manager will determine which elements of this information you can retrieve by clients.

To review, you should find your display name here:

var displayName = result.PlayerProfile.DisplayName
after following each of the links above.
7 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.

pfnathan avatar image pfnathan ♦ commented ·

All of our API calls work the same way, you have a request object, a response callback object and an error object. To answer your question, you would grab the result from the response callback and store it in a variable of your choosing. The example shows how to do this pretty well.

Below is the basic principle for any api call.

PlayFabClientApi.[methodName] ( [request object], [callback method], [error handling method] )

Therefore, your callback method would resemble something like this.

(result)=>{ 
    //Note, that the variable is some variable that I have made up
    //Also note that we grab the Display name from the result in our callback method. 
    var myVariable = result.PlayerProfile.Displayname
}


We do not provide general programming support, however I hope that the above example and response will help you on your way.

1 Like 1 ·
pmattei0 avatar image pmattei0 pfnathan ♦ commented ·

Yep thanks.

The principle of the api call wasnt lucid in my mind

I think I understood and it will be the right one for the next api call

void GetPlayerProfile(string playFabId)
{
PlayFabClientAPI.GetPlayerProfile(new GetPlayerProfileRequest()
{
PlayFabId = playFabId,
ProfileConstraints = new PlayerProfileViewConstraints()
{
ShowDisplayName = true
}

},
result => DisplayName = result.PlayerProfile.DisplayName,
error => Debug.LogError(error.GenerateErrorReport()));
}

Thanks again

1 Like 1 ·
pmattei0 avatar image pmattei0 commented ·

Thanks for your answer.

Before writing this topic I've read all thread that you had sent ( about player profile ) but the function that I need is written nowhere except in the tutorial ?

How can i know how to write a function that returns me the displayname in a variable with these links above ?

I probably have a bad method of analysis the API, that's why I'm asking you.

After reading all the link above many time I still dont know how to do :x

In general how to go about it ?

I guess it must be like this because it's shown in the tutorial...

void GetPlayerProfile(string playFabId)
{
PlayFabClientAPI.GetPlayerProfile(new GetPlayerProfileRequest()
{
PlayFabId = playFabId,
ProfileConstraints = new PlayerProfileViewConstraints()
{
ShowDisplayName = true
}

},
}
0 Likes 0 ·
pfnathan avatar image pfnathan ♦ commented ·

Here is the guide you should read: https://api.playfab.com/docs/tutorials/landing-players/getting-player-profiles

Specifically Step 2 - Making a player profile call

Also, one of the ways to find out API call behavior/ result would be running your API calls into Postman tool.

Execute PlayFab API Via Postman;

Knowing how to call the Web API methods manually is invaluable when you are trying to integrate PlayFab with your game. If a function isn’t working out quite how you expect, being able to call it in a tool that shows you the specific response data and any error messages is a powerful way to debug those calls. There are a number of tools out there that make it easy to interact directly with a Web API, but one that we really like is the Postman Chrome plugin.

This link https://api.playfab.com/docs/tutorials/execute-playfab-api-via-postman will give you step by step guide on how to test your API calls via Postman

0 Likes 0 ·
pmattei0 avatar image pmattei0 commented ·

You are telling that I need necessarily this Postman tool to get the displayname or I can use an unity script ?

0 Likes 0 ·
pmattei0 avatar image pmattei0 pmattei0 commented ·

As it's shown in the tutorial there is this function to get the player display name

voidGetPlayerProfile(string playFabId){
    PlayFabClientAPI.GetPlayerProfile(newGetPlayerProfileRequest(){
        PlayFabId = playFabId,
        ProfileConstraints =newPlayerProfileViewConstraints(){
            ShowDisplayName =true}}, 
    result => Debug.Log("The player's DisplayName profile data is: "+ result.PlayerProfile.DisplayName),
    error => Debug.LogError(error.GenerateErrorReport()));}

But I wonder how to stock it in a variable, Paul Gilmore was helping me about this.

I'm still wondering where to put this line, and how can I know that I must do that ?

var displayName = result.PlayerProfile.DisplayName

My thanks

0 Likes 0 ·
pmattei0 avatar image pmattei0 pmattei0 commented ·
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.