question

Rizwan Babar avatar image
Rizwan Babar asked

Google API error code: invalid_request details: Invalid Credentials

I am using playfab sdk in unity to login with play games. But when I call LoginWithGoogle request of playfab, I get this error:

 Error logging in player with custom ID: Google API error code: invalid_request details: Invalid Credentials
    
 <>c:<LoginWithGoogle>b__68_1(PlayFabError)
 System.Delegate:DynamicInvokeImpl(Object[])
 PlayFab.Internal.ResultContainer`1:WrapCallback(Delegate, Object)
 PlayFab.Internal.ResultContainer`1:HandleResults(CallRequestContainer, Delegate, ErrorCallback, Action`2)
 PlayFab.Internal.<MakeRequestViaUnity>d__14:MoveNext()
 UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

Here's my code to login:

     public void LoginGooglePlayGames()
     {
         PlayGamesPlatform.Instance.Authenticate((success) =>
         {
             if (success == SignInStatus.Success)
             {
                 Debug.Log("Login with Google Play games successful.");
    
                 PlayGamesPlatform.Instance.RequestServerSideAccess(false, code =>
                 {
                     Debug.Log("Authorization code: " + code);
                     Debug.Log("name " + PlayGamesPlatform.Instance.GetUserDisplayName());
                     playFabManager.LoginWithGoogle(code);
                 });
             }
             else
             {
                 Debug.Log("Login Unsuccessful");
             }
         });
     }
    
     public void LoginWithGoogle(int token)
     {
         LoginWithGoogleAccountRequest request = new LoginWithGoogleAccountRequest()
         {
             TitleId = PlayFabSettings.TitleId,
             CreateAccount = true,
             AccessToken = token
         };
            
         PlayFabClientAPI.LoginWithGoogleAccount(request, (result) =>
         {
             PlayFabId = result.PlayFabId;
             Debug.Log("Got PlayFabID: " + PlayFabId);
    
    
             if (result.NewlyCreated)
             {
                 Debug.Log("(new account)");
    
                 UserInfo info = new UserInfo();
                 info.PlayerName = GameManager.Instance.nameMy;
                 info.LoggedType = LoginType.Google.ToString();
                 info.Coins.Gold = StaticStrings.initCoinsCountFacebook;
                 info.Coins.Gems = StaticStrings.initGemsCountFacebook;
                 info.Meta.Avatar = -1;
                 info.Meta.AvatarURL = GameManager.Instance.AvatarURL;
                 info.Meta.UserID = GameManager.Instance.UserID;
                 Database.Instance.UpdateAllData(info);
             }
             else
             {
                 CheckIfFirstTitleLogin(PlayFabId, true);
                 Debug.Log("(existing account)");
             }
    
             GetPhotonToken();
    
         },
             (error) =>
             {
                 Debug.Log("Error logging in player with custom ID: " + error.ErrorMessage + "\n" + error.ErrorDetails);
                 GameManager.Instance.connectionLost.showDialog();
             });
     }

I have google addon installed on playfab. 6209-image-2023-08-01-123454644.png

And web client id created in google cloud platform

6216-image-2023-08-01-123539471.png

Authentication
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

·
Neils Shi avatar image
Neils Shi answered

For Unity, it’s not recommended to use LoginWithGoogleAccount anymore as Google Sign-In Unity Plugin hasn't been updated for many years. And the Google Unity plugin you are using is for GooglePlayGamesServices. For your scenario, you should use LoginWithGooglePlayGamesServices API instead.

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.