question

Bijian Wu avatar image
Bijian Wu asked

call Get Match on Server C#

Hi, I am using PlayFab Multiplayer and PlayFab Matchmaking, when i trying to call PlayFab.PlayFabMultiplayerAPI.GetMatch on server I get the following error says i have to logged in in order to call GetMatch, but does server needs to be logged in as well? or is there other method that should server call to get the current match?

PlayFabException: Must be logged in to call this method at PlayFab.PlayFabMultiplayerAPI.GetMatch (PlayFab.MultiplayerModels.GetMatchRequest request, System.Action`1[T] resultCallback, System.Action`1[T] errorCallback, System.Object customData, System.Collections.Generic.Dictionary`2[TKey,TValue] extraHeaders) [0x0002f] in <5be21a689d924a5390e337ae9fc78da2>:0 at PlayFabMultiplayerGameServerVMAgent+<GetMatchedPlayers>d__10.MoveNext () [0x00113] in <7ed52fe66e9748bfb7a78ddceb8823e2>:0

multiplayerMatchmaking
10 |1200

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

Rick Chen avatar image
Rick Chen answered

GetMatch API is an entity API which requires entity token, even for servers. If you would like to call this API in your own server, you could use the GetEntityToken API to get the entity token for your server.

For example, using the C# SDK:

var title_result = await
PlayFab.PlayFabAuthenticationAPI.GetEntityTokenAsync(new
PlayFab.AuthenticationModels.GetEntityTokenRequest { });

You could leave the GetEntityTokenRequest as empty, the call will returns the entity token for your server, then you could call the GetMatch API without error.

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

Bijian Wu avatar image Bijian Wu commented ·

When i tried your method, i get Unknown Error on server? I think I do need to pass in Entity ID in order for it to work?

0 Likes 0 ·
Rick Chen avatar image Rick Chen ♦ Bijian Wu commented ·

I have tested it without providing the entity key and it worked. From your description we could not determine the issue. Did you use the PlayFabAllSDK in C#? Could you please provide the code snippet of your implementations for us to diagnose it? When you provide the code snippet, please remove any personal information and any secret key for security reason.

0 Likes 0 ·
Bijian Wu avatar image Bijian Wu Rick Chen ♦ commented ·

I am using Unity C#, which that is why that might be different, following is the code snippet.

PlayFab.PlayFabAuthenticationAPI.GetEntityToken(new GetEntityTokenRequest(), OnGetServerEntityToken, OnGetServverEntityTokenFailed);

can you try it on Unity?

0 Likes 0 ·
Rick Chen avatar image
Rick Chen answered

Do you mean the Unity PlayFabSDK? It is different from C# PlayFabAllSDK. In Unity, you could use the following code:

 
PlayFab.PlayFabAuthenticationAPI.GetEntityToken(new PlayFab.AuthenticationModels.GetEntityTokenRequest { }, OnGetServerEntityToken, OnGetServverEntityTokenFailed);

However, by default the server API in PlayFabSDK is not enabled and you need to enable the server API first. You can do that in the PlayFab Editor Extension -> [SETTINGS] tab. The PlayFab Unity Editor Extensions can be download in here: https://github.com/PlayFab/UnitySDK

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

Bijian Wu avatar image Bijian Wu commented ·

Yeah, it is enabled, Can you test it On Unity server please, I am sure it is not working. and I use the same code as you.

0 Likes 0 ·
download.png (22.6 KiB)
Rick Chen avatar image Rick Chen ♦ Bijian Wu commented ·

I have tested it before providing the last answer, it worked. Here is my entire implementation:

public class Test : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        PlayFab.PlayFabAuthenticationAPI.GetEntityToken(new PlayFab.AuthenticationModels.GetEntityTokenRequest { }, OnGetServerEntityToken, OnGetServverEntityTokenFailed);
        }


    void OnGetServerEntityToken(PlayFab.AuthenticationModels.GetEntityTokenResponse res)
    {
        Debug.Log("Successful");
        Debug.Log(res.EntityToken);
    }


    void OnGetServverEntityTokenFailed(PlayFab.PlayFabError err)
    {
        Debug.Log(err.GenerateErrorReport());
    }


}

And here is the unity screenshot when I run the code, where the entity token is covered as it is a secret:

My unity version is 2019.4.13f1 and my PlayFabSDK version is 2.91.200730

From your description, I am not sure what is the cause of the issue. Could you please provide your Unity version and your PlayFabSDK version? Could you please describe the error you received in more detail?

0 Likes 0 ·
unity-test-work.png (39.6 KiB)
Bijian Wu avatar image Bijian Wu Rick Chen ♦ commented ·

I am using Unity2019.2.4f1, and PlayFab 2.95.200914, it just says error on server when I call the API.

0 Likes 0 ·
Show more comments
Rick Chen avatar image
Rick Chen answered

I used the same script above and run it on Unity2019.2.4f1, with the latest PlayFabSDK version 2.101.201218. It still worked.

The 400 BadRequest Error could be that the syntax of the request is invalid. Please try the following steps:

1. Update your PlayFabSDK to the latest version

2. Copy and paste the following code to your project

3. Run the code and see if it works

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class TestScript : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        PlayFab.PlayFabAuthenticationAPI.GetEntityToken(new PlayFab.AuthenticationModels.GetEntityTokenRequest { }, OnGetServerEntityToken, OnGetServverEntityTokenFailed);
    }


    void OnGetServerEntityToken(PlayFab.AuthenticationModels.GetEntityTokenResponse res)
    {
        Debug.Log("Successful");
        Debug.Log(res.EntityToken);
    }


    void OnGetServverEntityTokenFailed(PlayFab.PlayFabError err)
    {
        Debug.Log(err.GenerateErrorReport());
    }


}


If still not working, please provide the detail of the error that you receive.


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

Bijian Wu avatar image Bijian Wu commented ·

Hi, after I upgraded to latest PlayFab SDK and tried it out. i still got errors when using the same code as you. but this time got more info, I got 400 error code BadRequest, But got error message saying "ServiceUnavailable" and then bunch of Unknown Error for other type of error message. I think it is this ServiceUnavailable caused the problem,

I am using PlayFab Matchmaking and PlayFab Server by the way.

0 Likes 0 ·
Rick Chen avatar image Rick Chen ♦ Bijian Wu commented ·

The ServiceUnavailable error indicates that PlayFab may be having a temporary issue or the client is making too many API calls too quickly. Please refer to this document: https://docs.microsoft.com/en-us/gaming/playfab/api-references/global-api-method-error-codes#safe-to-retry-codes

It is not likely the PlayFab’s issue as my recent test was successful. It could be that you are making the API calls too quickly.

You mentioned you are using PlayFab Matchmaking and PlayFab Server, which API you used and caused the error? From your description, it is hard to tell what the real issue is. Please provide the code snippet where the error occurred and remove any personal information and secret key for security reason.

0 Likes 0 ·
Bijian Wu avatar image Bijian Wu Rick Chen ♦ commented ·

I am still getting the erros And I still tryting to log each error message out

err.GenerateErrorReport() = "/Authentication/GetEntityToken: Unknown Error"

err.ErrorMessage = "Unknown Error"

err.HttpCode = "400"

err.Error = "ServiceUnavailable"

err.HttpStatus = "BadRequest"

following are the codes, I put it in Coroutine with delay, after each failed callback, it is called again, but I am getting same error each time:

IEnumerator TryToLogServerIn() { yield return new WaitForSeconds(0.5f); PlayFab.PlayFabAuthenticationAPI.GetEntityToken(new PlayFab.AuthenticationModels.GetEntityTokenRequest { }, OnGetServerEntityToken, OnGetServverEntityTokenFailed); }

void OnGetServerEntityToken(PlayFab.AuthenticationModels.GetEntityTokenResponse res) { Debug.Log("Successful logged server in"); Debug.Log("Entity token is " + res.EntityToken); }

void OnGetServverEntityTokenFailed(PlayFab.PlayFabError err) { Debug.Log("err.GenerateErrorReport() " + err.GenerateErrorReport()); Debug.Log("err.ErrorMessage " + err.ErrorMessage); Debug.Log("err.HttpCode " + err.HttpCode); Debug.Log("err.Error " + err.Error); Debug.Log("err.HttpStatus " + err.HttpStatus); StartCoroutine(TryToLogServerIn()); }

0 Likes 0 ·
Bijian Wu avatar image
Bijian Wu answered

Do you think it might be because I have an empty PlayFabSharedSettings? thus means that I don't have project configed properly?


untitled.png (61.3 KiB)
10 |1200

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

Rick Chen avatar image
Rick Chen answered

Yes, the title id and developer secret key are required to call the server APIs. Could you please fill in your title id and secret key and try again? The secret key in your title can be found in [Your Game Manager]->[Title Settings]->[Secret Keys]. Please keep the secret key to yourself and not expose it to the public.

However, the unity should prompt you to fill the title id or the secret key if it is empty rather than presenting the ServiceUnavailable 400 badrequest error.

I also tried your code on my side, it worked.

It could be an issue with your environment. Could you please provide a fiddler trace of the issue network for us?


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

Bijian Wu avatar image Bijian Wu commented ·

Hi, I tried entered my Title Id and Devloper secret keys and it still does not work. and how to provide a fiddler trace of the issue network? I hosted my server on your multiplayer server and test the game there, and try to download the log about the live running server then I still getting the same errors.

following are the part of the secret keys screenshot? am I using the wrong secret keys? I tried both and both not working

0 Likes 0 ·
untitled.png (35.2 KiB)
Rick Chen avatar image Rick Chen ♦ Bijian Wu commented ·

You should use the default key. But I am not sure why it wasn’t working for you.

FiddlerCap is a lightweight tool that captures the web traffic logs, those logs help our engineer to find the cause of an issue, you can download it at this link: https://www.telerik.com/fiddler/fiddlercap

You could use the FiddlerCap as follow:

  1. Open the FiddlerCap, click the Start Capture button
  2. A new Internet Explorer window will appear, meaning it is start recording.
  3. Then open your Unity Project and reproduce the error.
  4. After that click the Stop Capture button inside FiddlerCap and click the Save Caption button to save the logs in a .SAZ file.
  5. Then you can provide the .SAZ file to us and we can diagnose it.
0 Likes 0 ·
Bijian Wu avatar image Bijian Wu Rick Chen ♦ commented ·

I didn't run the Unity server locally in my environment, I hosted my server in your multiplayer server then my client connect to it, all the errors I told were reported by the live server's log file

0 Likes 0 ·
Show more comments
Bijian Wu avatar image
Bijian Wu answered

F7AE3 is the title id

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

Bijian Wu avatar image Bijian Wu commented ·

I think the issue why all the Server API weren't working properly might be because I didn't set up the PlayFab Server API properly. because all the Client API works perfectly! Attached screenshot is for PlayFabEditorPrefsSO setting. can you point me if I missed something. Also, can you give me a step by step guide or full set up for the server API to work? I must have missed some of the setup? I grabbed the Server SDK package from here :https://github.com/PlayFab/gsdk/tree/master/UnityGsdk, might be this is the issue? where did you get your server SDK for Unity from? untitled.png

0 Likes 0 ·
untitled.png (29.6 KiB)
Rick Chen avatar image Rick Chen ♦ Bijian Wu commented ·

We inspected your title and cannot find the relevant error returned by GetEntityToken API. This means that the GetEntityToken API calls did not reach PlayFab. It is likely that the request you made was invalid. The PlayFabEditorPrefsSO is the settings for PlayFabEditorExtensions, it is not relevant to your API calls. You mentioned that you are using the UnityGsdk, the document said that you need to enable the scripting directive ENABLE_PLAYFABSERVER_API on your Build settings, like this screenshot. Could you please check that? Please also follow this document: Getting Started for Windows game servers using local Windows Containers to debug your unity server locally.

0 Likes 0 ·
Bijian Wu avatar image Bijian Wu Rick Chen ♦ commented ·

Everything is working while inside Unity Editor, but when host the server in PlayFab, Server API is not working anymore

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.