article

marcowilliamspf avatar image
marcowilliamspf posted

Unity: How do I get Google Plus Signin working using Google Play Games?

So I finally have a solution for this. It took a lot of research and banging the head against the keyboard, but alas we have an answer!

There are lots of step to this, and at some point I will be posting an official tutorial on the documentation site showing all the steps to get this working. For now, I'm going to post here but there are a few things you need to be aware of.

1> Current version of GPG (Google Play Games for unity) Really you only need v0.9.35 or higher.

2> The current version of GPG actually breaks the Push Notification Plugin because current GPG uses Support v4 v24.0.0 and our lib uses 23.1.1 and they removed some methods that we use. I'm working on a fix for the breakage, due to release early next week 1.9.2017 through 1.13.2017

3> You must follow the instructions (here) and setup OAuth 2.0 Client ID for Web <-- Very Important


Now that you have the above information, download the GPG and install it into your unity project. Then follow these next steps.

1> Setup your android project via GPG menu, below make sure the following information is complete. Client ID you got from the steps above. Your app_id is available in the google console. And make sure that the Enable Google Plus API Access checkbox is checked. Yes ignore the fact that it says not recommended. We do need to access Google+ APIs directly!

Now Initialize and get the token using the following code.

#if UNITY_ANDROID
        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
        .AddOauthScope("email")
        .AddOauthScope("profile")
        .RequireGooglePlus()
        .Build();


        PlayGamesPlatform.InitializeInstance(config);
        // recommended for debugging:
        PlayGamesPlatform.DebugLogEnabled = true;
        // Activate the Google Play Games platform
        PlayGamesPlatform.Activate();

            Social.localUser.Authenticate((success) =>
            {
                if (success)
                {
                    Debug.LogFormat("Id Token: {0}", idToken);
                    PlayFabClientAPI.LoginWithGoogleAccount(new LoginWithGoogleAccountRequest()
                    {
                        TitleId = PlayFabSettings.TitleId,
			//Now that we have successfully acquired an idToken, the AccessToken is now available. It is not until this callback is it available <-- That was the trick.
                        AccessToken = PlayGamesPlatform.Instance.GetAccessToken(),
                        CreateAccount = true,
                        InfoRequestParameters = new GetPlayerCombinedInfoRequestParams()
                        {
                            GetTitleData = true
                        }
                    }, (loginResult) =>
                    {
                        pushReadyToRegister = true;
                        Debug.Log("Login to playfab successful.");
                        Debug.Log(loginResult.PlayFabId);
                    }, OnPlayFabError);


                }
                else
                {
                    Debug.Log("Could not authenticate with the Google Sign In");
                }
               
               
            });
	
#endif
apis
10 |1200

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

Article

Contributors

MarcoWilliamsPF contributed to this article

Related Articles