question

andreighinea1 avatar image
andreighinea1 asked

GetServerAuthCode() from google login is always empty

I'm trying to save player data to a playfab account created from a google login. The google login process appears to be working almost ok, I can see my achievements and the login icon, but when I try to get the ServerAuthCode it's always empty.

This is my current code:

public class Achievements : MonoBehaviour {
    public PlayFabLogin PlayFabLogin;
#if UNITY_ANDROID
    PlayGamesClientConfiguration config;
#endif


#if UNITY_ANDROID || UNITY_IOS
    void Start ()
    {
#if UNITY_ANDROID
        if (PlayGamesPlatform.Instance.localUser.authenticated)
            return;
        config = new PlayGamesClientConfiguration.Builder()
            /*.AddOauthScope("profile")
            .AddOauthScope("email")
            .RequestIdToken()*/
            .RequestServerAuthCode(false)
            .Build();
        PlayGamesPlatform.InitializeInstance(config);
        PlayGamesPlatform.DebugLogEnabled = true;
        PlayGamesPlatform.Activate();
        PlayGamesPlatform.Instance.SignOut();
#elif UNITY_IOS
        if (Social.localUser.authenticated)
            return;
#endif
        SignIn();
    }
#endif


    void SignIn()
    {
#if UNITY_ANDROID || UNITY_IOS
        Social.localUser.Authenticate((bool success, string error) => {
            if (success)
            {
#if UNITY_ANDROID
                StartCoroutine(PlayFabLogin.LoginGoogle(config));
#endif
            }
            else
            {
                Debug.LogError("Login-Google login failed: " + error);
            }
        });
#endif
    }
}




And the PlayfabLogin class:
public class PlayFabLogin : MonoBehaviour
{
    public InputField EmailInputField, UsernameInputField, PasswordInputField;


#if !DISABLESTEAMWORKS
    LoginWithSteamRequest request;
#elif UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX
    LoginWithGameCenterRequest request;
#elif UNITY_XBOXONE
    //LoginWithXboxRequest request;
#endif


    public void Start()
    {
#if !DISABLESTEAMWORKS
        request = new LoginWithSteamRequest();
        PlayFabClientAPI.LoginWithSteam(request, OnLoginSuccess, OnLoginFailure);
#elif UNITY_ANDROID
        //LoginGoogle();
#elif UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX
        request = new LoginWithGameCenterRequest();
        request.CreateAccount = true;
        PlayFabClientAPI.LoginWithGameCenter(request, OnLoginSuccess, OnLoginFailure);
#elif UNITY_XBOXONE
        request = new LoginWithXboxRequest();
        request.CreateAccount = true;
        PlayFabClientAPI.LoginWithXbox(request, OnLoginSuccess, OnLoginFailure);
#endif
    }


#if UNITY_ANDROID
    public IEnumerator LoginGoogle(PlayGamesClientConfiguration config)
    {
        yield return new WaitForSecondsRealtime(5);
        string serverAuthCode = PlayGamesPlatform.Instance.GetServerAuthCode();


        Debug.Log("Login-LoginGoogle-Login with serverAuthCode: " + serverAuthCode);
        LoginWithGoogleAccountRequest request;
        request = new LoginWithGoogleAccountRequest()
        {
            TitleId = PlayFabSettings.TitleId,
            CreateAccount = true,
            ServerAuthCode = serverAuthCode
        };
    }
#endif




    private void OnLoginSuccess(LoginResult result)
    {
        Debug.Log("Congratulations, you made your first successful API call!\n Signed In as" + result.PlayFabId);
    }


    private void OnLoginFailure(PlayFabError error)
    {
        Debug.LogWarning("Something went wrong with your first API call.  :(");
        Debug.LogError("Here's some debug information:");
        Debug.LogError(error.GenerateErrorReport());
    }
}

asd

Player Datadata
10 |1200

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

1 Answer

·
Andy avatar image
Andy answered

That's not really a PlayFab issue, but an issue with the Google Play API for Unity. I did a quick search and found this open issue: https://github.com/playgameservices/play-games-plugin-for-unity/issues/2053. If you scroll down a bit, it looks like someone has proposed a work around. Good Luck!

10 |1200

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

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.