question

Darius Vu avatar image
Darius Vu asked

How to login with Google account (Not Google Play account)?

Hi support team,

Now I want to develop the function to login with google account. When an user clicks on the button "Login with Google" then the popup showing as below and user can choose the account to login. And it should work for both Android and IOS.

In Playfab, I am refering this tutorial: https://docs.microsoft.com/en-us/gaming/playfab/features/authentication/platform-specific-authentication/google-sign-in-unity

But I see that this is the login with Google Play Games and for only Android, not for Google account.

I also try the method as below:

    private void GoogleLoginProcessing()
    {
        if (GoogleSignIn.Configuration == null)
        {
            //Setting
            GoogleSignIn.Configuration = new GoogleSignInConfiguration
            {
                RequestIdToken = true,
                RequestEmail = true,
                WebClientId = "....e8i7v7ggir.apps.googleusercontent.com"
            };
        }
        Task<GoogleSignInUser> signIn = GoogleSignIn.DefaultInstance.SignIn();
        signIn.ContinueWith(task =>
        {
            if (task.IsCanceled == true)
            {
                Debug.LogError("Google log in task is canceled!");
                Debug.LogError(task.Exception);
            }
            else if (task.IsFaulted == true)
            {
                Debug.LogError("Google log in task is faulted!");
                Debug.LogError(task.Exception);
            }
            else
            {
                PlayfabManager.PlayFab.LoginWithGoogle(task.Result.IdToken, AfterLoginAction, errorCallbackGoogleLogin);
            }
        });
    }	
public void LoginWithGoogle(string googleAccessToken, Action<LoginResult> successCallback, Action<PlayFabError> errorCallback)
    {
        var request = new LoginWithGoogleAccountRequest()
        {
            TitleId = PlayFabSettings.TitleId,
            ServerAuthCode = googleAccessToken,
            CreateAccount = true,
        };
        PlayFabClientAPI.LoginWithGoogleAccount(request, successCallback, errorCallback);
    }

But it has the error: InvalidGoogleToken = 1026. So could you tell me how to implement the Google Login (not Google Play Games) as above, and it should work for android and IOS?

Thank you so much!

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.

Seth Du avatar image Seth Du ♦ commented ·

I have discussed with the team and will summarize the information for you. We thank you for your patience and understanding.

0 Likes 0 ·

1 Answer

·
Seth Du avatar image
Seth Du answered

According to the 2nd code snippet you show, in line 6, you used the googleAccessToken as the parameter for ServerAuthCode. Based on the API documentation LoginWithGoogleAccount, ServerAuthCode is not the access token, meanwhile according to the description, OAuth 2.0 server authentication code obtained on the client by calling the getServerAuthCode() (https://developers.google.com/identity/sign-in/android/offline-access) Google client API.

I understand that you would like to integrate Google Login in Unity with PlayFab that supports for Android and iOS. Currently, PlayFab doesn’t provide any detailed documentation about implementing Google sign in for iOS, but you may refer to: https://community.playfab.com/questions/25148/ios-integrating-playfab-with-google-signin.html

You can also check out the Google document below if you have any problem integrating Google Sign-in into your app:

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.

Darius Vu avatar image Darius Vu commented ·

I am grateful so much for your supports. Currently, I think that the best way is that I will develop the Google Play Games login method in Android and Apple ID login method in IOS.

But now I am facing the issue related to Google login method. You can check it in here and help me if you have any suggestion for me?

https://community.playfab.com/questions/44475/how-to-login-automatically-with-google-play-games.html

Many thanks, again.

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.