我确定我遗漏了一些愚蠢的东西但是在我检索并将 google id 令牌传递给 Unity 身份验证后我得到了错误:
[Authentication]: Request failed: 401, {"title":"PERMISSION_DENIED","detail":"validation failed","details":[],"status":401}
WebRequestException:{“标题”:“PERMISSION_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);
}
}
现在为时已晚,但在我阅读您的帖子时,我认为问题在于您传递了从 Google Play 游戏中检索到的授权令牌,但您正在尝试使用 Google 登录。使用 GPG 登录和使用 Google 登录是两件不同的事情。请改用 SignInWithGooglePlayGames。
我碰巧读了你 7 个月前的帖子,因为我最近在尝试使用 Google Play 游戏进行身份验证时遇到了同样的错误。但我的问题是我两次使用相同的令牌:第一次是尝试登录,第二次是登录,以防登录导致“已经链接到另一个玩家”异常。在第二次调用 Unity-GPG 链接之前,我不得不请求一个新的令牌。
我希望这可以帮助其他人,因为网上没有太多关于这方面的文献。