0
\$\begingroup\$

I've been trying to make this PlayFab+Photon Authentication script for my multiplayer game from this Photon quickstart guide but I got this error I have been trying to resolve:

error screenshot

🗨 PlayFab Authentication using custom ID

🗨 PlayFab authenticated, requesting photon token...

❗ [Error] | /Client/GetPhotonAuthenticationToken: PhotonApplicationNotFound

Is anything wrong within my script?

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

public class PlayFabAuthentication : Photon.MonoBehaviour
{
    private string PlayerIDCache = "";

    private void Awake()
    {
        AuthWithPlayFab();
    }

    private void AuthWithPlayFab()
    {
        Debug.Log("PlayFab Authenticating using custom ID");
        LoginWithCustomIDRequest request = new LoginWithCustomIDRequest();
        request.CreateAccount = true;
        request.CustomId = PlayFabSettings.DeviceUniqueIdentifier;
        PlayFabClientAPI.LoginWithCustomID(request, RequestToken, OnError);
    }

    void RequestToken(LoginResult result)
    {
        Debug.Log("PlayFab authenticated, Requesting photon token...");
        PlayerIDCache = result.PlayFabId;
        GetPhotonAuthenticationTokenRequest request = new GetPhotonAuthenticationTokenRequest();
        request.PhotonApplicationId = PhotonNetwork.PhotonServerSettings.AppID;
        PlayFabClientAPI.GetPhotonAuthenticationToken(request, AuthWithPhoton, OnError);
    }

    void AuthWithPhoton(GetPhotonAuthenticationTokenResult result)
    {
        Debug.Log("Photon token acquired: " + result.PhotonCustomAuthenticationToken + " Authentication complete.");
        var CustomAuth = new AuthenticationValues { AuthType = CustomAuthenticationType.Custom };
        CustomAuth.AddAuthParameter("username", PlayerIDCache);
        CustomAuth.AddAuthParameter("token", result.PhotonCustomAuthenticationToken);
        PhotonNetwork.AuthValues = CustomAuth;
    }

    void OnError(PlayFabError error)
    {
        Debug.LogError($"[ERROR] | {error.GenerateErrorReport()}");
    }
}
\$\endgroup\$
1
  • \$\begingroup\$ UnityScript has not been supported in Unity for 3 years now. Please do not use this tag for questions about C# code. \$\endgroup\$
    – DMGregory
    Sep 11 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.