question

robertfickensher avatar image
robertfickensher asked

PlayFabAuthenticator script error while trying to connect photon with playfab.,PlayFabAuthentication gives errors.

So, I am developing a virtual reality monkey game and when I try to connect playfab and photon, I do it all but when I import PlayFabAuthentication. it will give me errors. My unity version is 2021.3.26f1 The errors it gives me are theese.

Assets\Scripts\PlayFabDevEx\PlayFabAuthenticator.cs(60,35): error CS0103: The name 'PhotonNetwork' does not exist in the current context

Assets\Scripts\PlayFabDevEx\PlayFabAuthenticator.cs(74,80): error CS0103: The name 'CustomAuthenticationType' does not exist in the current context

Assets\Scripts\PlayFabDevEx\PlayFabAuthenticator.cs(83,9): error CS0103: The name 'PhotonNetwork' does not exist in the current context

Assets\Scripts\PlayFabDevEx\PlayFabAuthenticator.cs(110,22): error CS0103: The name 'PhotonNetwork' does not exist in the current context

Assets\Scripts\PlayFabDevEx\PlayFabAuthenticator.cs(110,67): error CS0246: The type or namespace name 'RaiseEventOptions' could not be found (are you missing a using directive or an assembly reference?)

Assets\Scripts\PlayFabDevEx\PlayFabAuthenticator.cs(119,9): error CS0103: The name 'PhotonNetwork' does not exist in the current context

If you have a solution please tell me.

Authenticationphoton
10 |1200

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

Neils Shi avatar image
Neils Shi answered

Have you followed the document : Photon Quickstart - PlayFab | Microsoft Learn (https://learn.microsoft.com/en-us/gaming/playfab/sdks/photon/quickstart) to integrate Photon with PlayFab?

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.

robertfickensher avatar image robertfickensher commented ·

Yes, I did it just gives me errors

0 Likes 0 ·
Neils Shi avatar image
Neils Shi answered

I can't reproduce your error, I followed the documentation Photon Quickstart - PlayFab | Microsoft Learn (https://learn.microsoft.com/en-us/gaming/playfab/sdks/photon/quickstart) to integrate PlayFab with Photon and it works fine. Have you used Photon Unity Networking Classic (https://assetstore.unity.com/packages/tools/network/photon-unity-networking-classic-free-1786) to test? In addition, you can refer to the following testing code:

 using PlayFab;
 using PlayFab.ClientModels;
 using UnityEngine;
    
 public class PlayFabAuthenticator : MonoBehaviour
 {
    
     private string _playFabPlayerIdCache;
    
     //Run the entire thing on awake
     public void Awake()
     {
         AuthenticateWithPlayFab();
     }
    
     /*
      * Step 1
      * We authenticate a current PlayFab user normally.
      * In this case we use the LoginWithCustomID API call for simplicity.
      * You can absolutely use any Login method you want.
      * We use PlayFabSettings.DeviceUniqueIdentifier as our custom ID.
      * We pass RequestPhotonToken as a callback to be our next step, if
      * authentication was successful.
      */
     private void AuthenticateWithPlayFab()
     {
         LogMessage("PlayFab authenticating using Custom ID...");
    
         PlayFabClientAPI.LoginWithCustomID(new LoginWithCustomIDRequest()
         {
             CreateAccount = true,
             CustomId = PlayFabSettings.DeviceUniqueIdentifier
         }, RequestPhotonToken, OnPlayFabError);
     }
    
     /*
     * Step 2
     * We request a Photon authentication token from PlayFab.
     * This is a crucial step, because Photon uses different authentication tokens
     * than PlayFab. Thus, you cannot directly use PlayFab SessionTicket and
     * you need to explicitly request a token. This API call requires you to
     * pass a Photon App ID. The App ID may be hard coded, but in this example,
     * we are accessing it using convenient static field on PhotonNetwork class.
     * We pass in AuthenticateWithPhoton as a callback to be our next step, if
     * we have acquired the token successfully.
     */
     private void RequestPhotonToken(LoginResult obj)
     {
         LogMessage("PlayFab authenticated. Requesting photon token...");
    
         //We can player PlayFabId. This will come in handy during next step
         _playFabPlayerIdCache = obj.PlayFabId;
    
         PlayFabClientAPI.GetPhotonAuthenticationToken(new GetPhotonAuthenticationTokenRequest()
         {
             PhotonApplicationId = PhotonNetwork.PhotonServerSettings.AppID
         }, AuthenticateWithPhoton, OnPlayFabError);
     }
    
     /*
      * Step 3
      * This is the final and the simplest step. We create a new AuthenticationValues instance.
      * This class describes how to authenticate a player inside the Photon environment.
      */
     private void AuthenticateWithPhoton(GetPhotonAuthenticationTokenResult obj)
     {
         LogMessage("Photon token acquired: " + obj.PhotonCustomAuthenticationToken + "  Authentication complete.");
    
         //We set AuthType to custom, meaning we bring our own, PlayFab authentication procedure.
    
         var customAuth = new AuthenticationValues { AuthType = CustomAuthenticationType.Custom };
    
         //We add "username" parameter. Do not let it confuse you: PlayFab is expecting this parameter to contain player PlayFab ID (!) and not username.
         customAuth.AddAuthParameter("username", _playFabPlayerIdCache);    // expected by PlayFab custom auth service
    
         //We add "token" parameter. PlayFab expects it to contain Photon Authentication Token issues to your during previous step.
         customAuth.AddAuthParameter("token", obj.PhotonCustomAuthenticationToken);
    
         //We finally tell Photon to use this authentication parameters throughout the entire application.
         PhotonNetwork.AuthValues = customAuth;
     }
    
     private void OnPlayFabError(PlayFabError obj)
     {
         LogMessage(obj.GenerateErrorReport());
     }
    
     public void LogMessage(string message)
     {
         Debug.Log("PlayFab + Photon Example: " + message);
     }
 }
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.

robertfickensher avatar image robertfickensher commented ·

I don't know if I didn't add this but I am using PUN 2 not PUN Classic. I think thats the reason why but my game would work if I used PUN Classic.

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.