question

Leyla Ahmedzadeh avatar image
Leyla Ahmedzadeh asked

How to get other player's PlayFabId in mathcmaking

In my game, 2 players can be matched together. Is it possible to get other player's PlayFabId ? I've managed to get the EntityId of other player tha's matched with me.

This is code that i am using for mathcmaking

PlayFabMultiplayerAPI.CreateMatchmakingTicket(
                new CreateMatchmakingTicketRequest
                {
                    Creator = new MatchmakingPlayer
                    {
                        Entity = new EntityKey
                        {
                            Id = playerEntityId,
                            Type = "title_player_account"
                        },
                        Attributes = new MatchmakingPlayerAttributes
                        {
                            DataObject = new { }
                        }
                    },
                    GiveUpAfterSeconds = 120,
                    QueueName = queueName
                },
                OnMatchmakingTicketCreated,
                OnMatchmakingError);
Matchmaking
10 |1200

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

Made Wang avatar image
Made Wang answered

You can get the corresponding player's PlayFabId via GetProfile.

//Azure Function Cloud Script
        [FunctionName("GetPlayFabId")]
        public static async Task<IActionResult> GetPlayFabId(
             [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
             ILogger log)
        {
            FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());
            var settings = new PlayFabApiSettings
            {
                TitleId = context.TitleAuthenticationContext.Id
            };
            var authContext = new PlayFabAuthenticationContext
            {
                EntityToken = context.TitleAuthenticationContext.EntityToken
            };
            string EntityId=context.FunctionArgument["EntityId"];
            string EntityType=context.FunctionArgument["EntityType"];


            var profilesApi=new PlayFabProfilesInstanceAPI(settings,authContext);
            var getProfileRequest=new GetEntityProfileRequest()
            {
                Entity=new PlayFab.ProfilesModels.EntityKey{
                    Id=EntityId,
                    Type=EntityType
                }
            };
            var result =await profilesApi.GetProfileAsync(getProfileRequest);
            return new OkObjectResult(new{
                    PlayFabId=result.Result.Profile.Lineage.MasterPlayerAccountId
                });
        } 

//Client
    public void Execute()
    {
        PlayFabCloudScriptAPI.ExecuteFunction(new ExecuteFunctionRequest
        {
            FunctionName = "GetPlayFabId",
            FunctionParameter = new Dictionary<string, object>
            {
                {"EntityId"," " },
                {"EntityType"," " }
            }
        },
        (result) =>
        {
            Debug.Log("Execute Success");
            Debug.Log(result.FunctionResult);
        },
        (error) =>
        {
            Debug.LogError(error.GenerateErrorReport());
        });
    }


10 |1200

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

Leyla Ahmedzadeh avatar image
Leyla Ahmedzadeh answered

I did this and got this error. Is there authorization settings in PlayFab that i can activate ?

erorr.png


erorr.png (11.1 KiB)
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.

Made Wang avatar image Made Wang commented ·

Sorry for not explaining in advance, calling this API on the client side can only get data related to the caller. If you want to get other player's data, you can call it on Azure Function Cloud Script. I modified the above code, you can refer to.

0 Likes 0 ·
Leyla Ahmedzadeh avatar image Leyla Ahmedzadeh commented ·

I added this code to title settings->API feature


  1. {
  2. "Action":"Read",
  3. "Effect":"Allow",
  4. "Resource":"pfrn:data--*!*/Profile/Objects/*",
  5. "Principal":"*",
  6. "Comment":"Allow objects profile access",
  7. "Condition":null
  8. }

This code was posted in this question: https://community.playfab.com/questions/62789/how-to-get-others-data-object.html

Now it works

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.