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.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Firebase.Auth;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine.SocialPlatforms;
public class GoogleAuthentication : MonoBehaviour
{
public static GoogleAuthentication instance;
public delegate void Authenticated();
public static event Authenticated OnAuthenticated;
public delegate void AuthenticationFailed();
public static event AuthenticationFailed OnAuthenticationFailed;
private string _authCode;
public FirebaseUser user { get; private set; }
public string userID { get; private set; }
// Start is called before the first frame update
void Awake()
{
if (instance != null)
{
Destroy(this.gameObject);
}
else
{
instance = this;
DontDestroyOnLoad(instance);
}
}
private void Start()
{
Authenticate();
}
public void Authenticate()
{
ConfigurePlayGamesClient();
SignIn();
}
private void ConfigurePlayGamesClient()
{
PlayGamesClientConfiguration config =
new PlayGamesClientConfiguration.Builder()
.RequestEmail()
.RequestServerAuthCode(false)
.RequestIdToken()
.Build();
PlayGamesPlatform.Instance.GetIdToken();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
Debug.Log("Configured Google Play Games Client");
}
private void SignIn()
{
PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptOnce, (result) => {
// handle results
if(result == SignInStatus.Success)
{
Debug.Log("Signed into google play games");
_authCode = PlayGamesPlatform.Instance.GetServerAuthCode();
CreateFirebaseUser();
}
else
{
Debug.Log("Unable to sign into google play!");
}
});
//Social.localUser.Authenticate((bool success) =>
//{
// if (success == true)
// {
// Debug.Log("Signed into google play games");
// _authCode = PlayGamesPlatform.Instance.GetServerAuthCode();
// CreateFirebaseUser();
// }
// else
// {
// Debug.Log("Unable to sign into google play!");
// }
//});
}
private IEnumerator RetryLogin(float sleep)
{
yield return new WaitForSecondsRealtime(sleep);
SignIn();
}
private void CreateFirebaseUser()
{
FirebaseAuth auth = FirebaseAuth.DefaultInstance;
Credential credential =
PlayGamesAuthProvider.GetCredential(_authCode);
auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
if (task.IsCanceled)
{
Debug.LogError("SignInWithCredentialAsync was canceled.");
return;
}
if (task.IsFaulted)
{
Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
return;
}
FirebaseUser newUser = task.Result;
Debug.LogFormat("User signed in successfully: {0} ({1})",
newUser.DisplayName, newUser.UserId);
});
user = auth.CurrentUser;
OnAuthenticated();
if (user != null)
{
Debug.Log("Signed into firebase");
string playerName = user.DisplayName;
// The user's Id, unique to the Firebase project.
// Do NOT use this value to authenticate with your backend server, if you
// have one; use User.TokenAsync() instead.
string uid = user.UserId;
}
else
{
Debug.Log("Unable to sign into firebase");
//Unable to sign in
}
}
}

