Android的Unity身份验证-InginwithGoogogleassync授予许可

发布于 2025-02-13 02:43:53 字数 1957 浏览 0 评论 0原文

我敢肯定我缺少一些愚蠢的东西,但是在我检索并将Google ID令牌传递给Unity身份验证之后,我会遇到错误:

[authentication]:请求失败:401,{“ title”:“ cermission_denied”,“”详细信息“:“验证失败”,“详细信息”:[],“状态”:401}

webrequestexexception: {“ title”:“ cermission_denied”,“详细”:“验证失败”,“详细信息”:[],“状态”:401}

以下是我的代码,任何帮助:

async void Awake()
     {
         await UnityServices.InitializeAsync();
         InitializePlayGamesLogin();
     }
 
     void InitializePlayGamesLogin()
     {
         PlayGamesPlatform.Activate();
     }
 
     // Call when login button is pressed
     public void LoginGooglePlayGames()
     {       
         Social.localUser.Authenticate(OnGooglePlayGamesLogin);
     }
 
     //Check login success
     async void OnGooglePlayGamesLogin(bool success)
     {
         if (success)
         {
             // Call Unity Authentication SDK to sign in or link with Google.
             string idToken = PlayGamesPlatform.Instance.GetUserId();
             await SignInWithGoogleAsync(idToken);                          
         }
         else
         {
             Debug.Log("Unsuccessful login");
         }
     }
 
     async Task SignInWithGoogleAsync(string idToken)
     {
         try
         {
             await AuthenticationService.Instance.SignInWithGoogleAsync(idToken);
             Debug.Log("SignIn is successful.");
             //if sign in successful turn off login screen.
             loginScreen.SetActive(false);
         }
         catch (AuthenticationException ex)
         {
             // Compare error code to AuthenticationErrorCodes
             // Notify the player with the proper error message
             Debug.LogException(ex);
         }
         catch (RequestFailedException ex)
         {
             // Compare error code to CommonErrorCodes
             // Notify the player with the proper error message
             Debug.LogException(ex);
         }
     }

I'm sure I'm missing something silly but after I retrieve and pass the google id token to Unity Authentication I get the errors:

[Authentication]: Request failed: 401, {"title":"PERMISSION_DENIED","detail":"validation failed","details":[],"status":401}

WebRequestException: {"title":"PERMISSION_DENIED","detail":"validation failed","details":[],"status":401}

Below is my code, any help appreciated:

async void Awake()
     {
         await UnityServices.InitializeAsync();
         InitializePlayGamesLogin();
     }
 
     void InitializePlayGamesLogin()
     {
         PlayGamesPlatform.Activate();
     }
 
     // Call when login button is pressed
     public void LoginGooglePlayGames()
     {       
         Social.localUser.Authenticate(OnGooglePlayGamesLogin);
     }
 
     //Check login success
     async void OnGooglePlayGamesLogin(bool success)
     {
         if (success)
         {
             // Call Unity Authentication SDK to sign in or link with Google.
             string idToken = PlayGamesPlatform.Instance.GetUserId();
             await SignInWithGoogleAsync(idToken);                          
         }
         else
         {
             Debug.Log("Unsuccessful login");
         }
     }
 
     async Task SignInWithGoogleAsync(string idToken)
     {
         try
         {
             await AuthenticationService.Instance.SignInWithGoogleAsync(idToken);
             Debug.Log("SignIn is successful.");
             //if sign in successful turn off login screen.
             loginScreen.SetActive(false);
         }
         catch (AuthenticationException ex)
         {
             // Compare error code to AuthenticationErrorCodes
             // Notify the player with the proper error message
             Debug.LogException(ex);
         }
         catch (RequestFailedException ex)
         {
             // Compare error code to CommonErrorCodes
             // Notify the player with the proper error message
             Debug.LogException(ex);
         }
     }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眉目亦如画i 2025-02-20 02:43:53

现在为时已晚,但是当我阅读您的帖子时,我认为问题是您通过Google Play Games检索的授权令牌,但您正在尝试与Google登录。与GPG和Google签约是两件事。改用SignInwithGooglePlayGames。

我碰巧阅读了您7个月大的帖子,因为最近尝试使用Google Play游戏进行身份验证时,我遇到了同样的错误。但是我的问题是,我两次使用同样的令牌:首先是尝试登录,其次是登录,以防登录导致“已经链接到另一个玩家”例外。在第二次拨打Unity-GPG链接之前,我必须要求新的令牌。

我希望这可以帮助他人,因为在线上没有太多文献。

Too late now, but as I'm reading your post I'm thinking the issue is that your passing an authorization token you retrieve from Google Play Games but you're trying to sign in with Google. Signing in with GPG and Google are two different things. Use SignInWithGooglePlayGames instead.

I happen to read your 7 months old post because I've lately got the same error when trying to authenticate with Google Play Games. But my issue was that I was using the same token twice: firstly by trying to log in and secondly to sign in in case the login resulted in the "already linked to another player" exception. I had to request a new token before calling the Unity-GPG link for the second time.

I hope this can help others, as there's not much literature online about this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文