我想通过Google Play游戏使用身份验证,但总是在第二次登录或链接请求(第一次成功)后获得:
Firebase.FirebaseException:发生内部错误。 [从GOOGLE_PLAY_GAMES获取访问令牌时出错,OAuth2重定向uri为:http://localhost,响应:OAuth2TokenResponse {params:error = invalid_grant&error_description = Bad%20Request,httpMetadata:HttpMetadata {status = 400,cachePolicy = NO_CACHE,cacheDuration = null,cacheImm ,staleWhileRevalidate = null,filename = null,lastModified = null,headers = HTTP / 1.1 200 OK,cookieList = []}}]
删除用户后,登录名将再次正常工作。我应该在firebase控制台中设置一些内容来解决此问题吗?
验证GPG脚本:
public void Init()
{
PlayGamesHelperObject.CreateObject();
PlayGamesHelperObject.RunOnGameThread(() =>
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.RequestServerAuthCode(false)
.Build();
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.InitializeInstance(config);
Social.Active = PlayGamesPlatform.Activate();
});
}
public void Authenticate(Action<bool, ILocalUser, string> onAuth)
{
if (Social.localUser == null)
{
onAuth.Invoke(false, Social.localUser, string.Empty);
return;
}
if (Social.localUser.authenticated)
{
onAuth.Invoke(true, Social.localUser, PlayGamesPlatform.Instance.GetServerAuthCode());
return;
}
PlayGamesHelperObject.RunOnGameThread(() =>
{
Social.Active.Authenticate(Social.localUser, (status)=>
{
onAuth.Invoke(status, Social.localUser, PlayGamesPlatform.Instance.GetServerAuthCode());
});
});
}
授权时调用:
private FirebaseUser User { get; set; }
private GoogleAuth Auth { get; set; }
event Action<Exception> onSingInFailed = delegate { };
event Action<FirebaseUser> onSignInSocials = delegate { };
event Action<FirebaseUser> onLinkInSocials = delegate { };
public void OnSocialsLogin(bool status, ILocalUser user, string authCode)
{
if(status)
{
Credential credential = PlayGamesAuthProvider.GetCredential(authCode);
if (User == null)
Auth.SignInWithCredential(credential, onSignInSocials, onSingInFailed);
else
Auth.LinkWithCredential(User, credential, onLinkInSocials, (exc) =>
{
onLinkFailed.Invoke(exc);
Auth.SignInWithCredential(credential, onSignInSocials, onSingInFailed);
});
}
}
GoogleAuth类的一部分:
private static FirebaseAuth Auth { get; set; }
public void SignInWithCredential(Credential credential, Action<FirebaseUser> onSignIn, Action<Exception> onFailure, Action onCanceled = default(Action))
{
if (onCanceled == null)
onCanceled = delegate { };
Auth.SignInWithCredentialAsync(credential).ContinueWith(task =>
{
if (task.IsCanceled)
onCanceled.Invoke();
else if (task.IsFaulted)
onFailure.Invoke(task.Exception);
else if (task.IsCompleted)
onSignIn.Invoke(task.Result);
});
}
public void LinkWithCredential(FirebaseUser user, Credential credential, Action<FirebaseUser> onLinkIn, Action<Exception> onFailure, Action onCanceled = default(Action))
{
if (onCanceled == null)
onCanceled = delegate { };
user.LinkWithCredentialAsync(credential).ContinueWith(task =>
{
if (task.IsCanceled)
onCanceled.Invoke();
else if (task.IsFaulted)
onFailure.Invoke(task.Exception);
else if (task.IsCompleted)
onLinkIn.Invoke(task.Result);
});
}
我知道已经有一段时间了,但是您是否设法解决了这个问题?我正在为完全相同的案例而苦苦挣扎,而且想法不多了。