Search Unity

Question Unable to get Google Play Games Services sign-in to work with Android game

Discussion in 'Formats & External Tools' started by collinpatrick15, Sep 26, 2020.

  1. collinpatrick15

    collinpatrick15

    Joined:
    Nov 7, 2018
    Posts:
    38
    For the past week, I have been fighting an uphill battle trying to get Google Play Games Services (GPGS) to authenticate and log in a user for my game. I am mostly using the sample code provided in the getting started guide provided by Google and as far as I can tell it is working as intended.

    My problem is when I build my game to my Android device, the sign-in process fails before even being prompted to enter any sign-in info. I get the little banner that appears at the top of the screen that says connecting to google play games, then it disappears and shows a loading wheel for a few seconds before ultimately failing.

    I have looked at the adb logcat and the only error I can get is "[Play Games Plugin 0.10.11] 09/26/20 16:28:53 -05:00 ERROR: No client available, returning null." I have scoured google but could not find anything that will fix this. There is a lot of conflicting documentation for the plugin when using Unity 2020 so this really has not made it easy. I have also tried everything I could possibly think of in the Google play console and API settings to get this to work.

    I attached images of the full adb log. I also attached my code on the off chance it's the problem.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Firebase.Auth;
    5. using GooglePlayGames;
    6. using GooglePlayGames.BasicApi;
    7. using UnityEngine.SocialPlatforms;
    8.  
    9. public class GoogleAuthentication : MonoBehaviour
    10. {
    11.     public static GoogleAuthentication instance;
    12.  
    13.     public delegate void Authenticated();
    14.     public static event Authenticated OnAuthenticated;
    15.  
    16.     public delegate void AuthenticationFailed();
    17.     public static event AuthenticationFailed OnAuthenticationFailed;
    18.  
    19.     private string _authCode;
    20.     public FirebaseUser user { get; private set; }
    21.     public string userID { get; private set; }
    22.     // Start is called before the first frame update
    23.     void Awake()
    24.     {
    25.         if (instance != null)
    26.         {
    27.             Destroy(this.gameObject);
    28.         }
    29.         else
    30.         {
    31.             instance = this;
    32.             DontDestroyOnLoad(instance);
    33.         }
    34.     }
    35.  
    36.     private void Start()
    37.     {
    38.         Authenticate();
    39.     }
    40.  
    41.     public void Authenticate()
    42.     {
    43.         ConfigurePlayGamesClient();
    44.         SignIn();
    45.     }
    46.  
    47.     private void ConfigurePlayGamesClient()
    48.     {
    49.         PlayGamesClientConfiguration config =
    50.         new PlayGamesClientConfiguration.Builder()
    51.         .RequestEmail()
    52.         .RequestServerAuthCode(false)
    53.         .RequestIdToken()
    54.         .Build();
    55.  
    56.         PlayGamesPlatform.Instance.GetIdToken();
    57.  
    58.         PlayGamesPlatform.InitializeInstance(config);
    59.         PlayGamesPlatform.DebugLogEnabled = true;
    60.         PlayGamesPlatform.Activate();
    61.  
    62.         Debug.Log("Configured Google Play Games Client");
    63.     }
    64.  
    65.     private void SignIn()
    66.     {
    67.         PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptOnce, (result) => {
    68.             // handle results
    69.             if(result == SignInStatus.Success)
    70.             {
    71.                 Debug.Log("Signed into google play games");
    72.                 _authCode = PlayGamesPlatform.Instance.GetServerAuthCode();
    73.                 CreateFirebaseUser();
    74.             }
    75.             else
    76.             {
    77.                 Debug.Log("Unable to sign into google play!");
    78.            
    79.             }
    80.         });
    81.  
    82.         //Social.localUser.Authenticate((bool success) =>
    83.         //{
    84.         //    if (success == true)
    85.         //    {
    86.         //        Debug.Log("Signed into google play games");
    87.         //        _authCode = PlayGamesPlatform.Instance.GetServerAuthCode();
    88.         //        CreateFirebaseUser();
    89.         //    }
    90.         //    else
    91.         //    {
    92.         //        Debug.Log("Unable to sign into google play!");
    93.         //    }
    94.         //});
    95.     }
    96.  
    97.     private IEnumerator RetryLogin(float sleep)
    98.     {
    99.         yield return new WaitForSecondsRealtime(sleep);
    100.         SignIn();
    101.     }
    102.  
    103.     private void CreateFirebaseUser()
    104.     {
    105.         FirebaseAuth auth = FirebaseAuth.DefaultInstance;
    106.         Credential credential =
    107.         PlayGamesAuthProvider.GetCredential(_authCode);
    108.         auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
    109.             if (task.IsCanceled)
    110.             {
    111.                 Debug.LogError("SignInWithCredentialAsync was canceled.");
    112.                 return;
    113.             }
    114.             if (task.IsFaulted)
    115.             {
    116.                 Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
    117.                 return;
    118.             }
    119.  
    120.             FirebaseUser newUser = task.Result;
    121.             Debug.LogFormat("User signed in successfully: {0} ({1})",
    122.                 newUser.DisplayName, newUser.UserId);
    123.         });
    124.  
    125.         user = auth.CurrentUser;
    126.  
    127.         OnAuthenticated();
    128.  
    129.         if (user != null)
    130.         {
    131.             Debug.Log("Signed into firebase");
    132.             string playerName = user.DisplayName;
    133.  
    134.             // The user's Id, unique to the Firebase project.
    135.             // Do NOT use this value to authenticate with your backend server, if you
    136.             // have one; use User.TokenAsync() instead.
    137.             string uid = user.UserId;
    138.         }
    139.         else
    140.         {
    141.             Debug.Log("Unable to sign into firebase");
    142.             //Unable to sign in
    143.         }
    144.     }
    145.  
    146. }
    Log1.PNG Log2.PNG
    View attachment 706464
     
    Last edited: Sep 27, 2020
    javierron likes this.
  2. QuebecDev

    QuebecDev

    Joined:
    May 9, 2020
    Posts:
    37
    Same problem
     
  3. ZoroArts_dev

    ZoroArts_dev

    Joined:
    Jun 2, 2020
    Posts:
    1
    Me too
    The same situation. Logging in Message showing but then it disappears
     
  4. javierron

    javierron

    Joined:
    May 17, 2020
    Posts:
    1
    Same issue, any workaround?
     
  5. R0oo0T

    R0oo0T

    Joined:
    Oct 25, 2012
    Posts:
    8
    Me too, Same issue