gpt4 book ai didi

c# - 如何使用 Firebase 统一创建 Facebook 登录?

转载 作者:太空宇宙 更新时间:2023-11-03 12:12:30 50 4
gpt4 key购买 nike

所以我尝试使用 Firebase 来统一并为我的项目创建一个 Facebook 登录。

我遵循了 firebase 文档和 Facebook 开发人员中的所有说明,包括将 SDK 导入我的项目并在 Facebook 登录中添加 appID keyhashes 单独工作正常但是一旦我尝试将它发送到 Firebase 以保持登录信息我一直收到异常。

这是我的代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Facebook.Unity;

public class facebookLogin : MonoBehaviour {

// Use this for initialization
void Awake()
{
if (!FB.IsInitialized)
{
// Initialize the Facebook SDK
FB.Init(InitCallback, OnHideUnity);
}
else
{
// Already initialized, signal an app activation App Event
FB.ActivateApp();
}
}
private void InitCallback()
{
if (FB.IsInitialized)
{
// Signal an app activation App Event
FB.ActivateApp();
// Continue with Facebook SDK
// ...
}
else
{
Debug.Log("Failed to Initialize the Facebook SDK");
}
}

private void OnHideUnity(bool isGameShown)
{
if (!isGameShown)
{
// Pause the game - we will need to hide
Time.timeScale = 0;
}
else
{
// Resume the game - we're getting focus again
Time.timeScale = 1;
}
}
public void FBlogin()
{
List<string> permissions = new List<string>();
permissions.Add("public_profile");
permissions.Add("email");
permissions.Add("user_friends");
FB.LogInWithReadPermissions(permissions, AuthCallback);
}
private void AuthCallback(ILoginResult result)
{
if (FB.IsLoggedIn)
{
Firebase.Auth.FirebaseAuth auth =
Firebase.Auth.FirebaseAuth.DefaultInstance;
List<string> permissions = new List<string>();

// AccessToken class will have session details
var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
// Print current access token's User ID
Debug.Log(aToken.TokenString);
Debug.Log(aToken.UserId);


Firebase.Auth.Credential credential =

Firebase.Auth.FacebookAuthProvider.GetCredential(aToken.TokenString);
auth.SignInWithCredentialAsync(credential).ContinueWith(task
=> {
if (task.IsCanceled)
{
Debug.LogError("SignInWithCredentialAsync was
canceled.");
return;
}
if (task.IsFaulted)
{
Debug.LogError("SignInWithCredentialAsync encountered
an error: " + task.Exception);
return;
}

Firebase.Auth.FirebaseUser newUser = task.Result;
Debug.LogFormat("User signed in successfully: {0} ({1})",
newUser.DisplayName, newUser.UserId);
});
// Print current access token's granted permissions
//foreach(string perms in aToken.Permissions)
//{
// Debug.Log(perms);
//}
}
else
{
Debug.Log("User cancelled login");
}
}
}

这里是我的异常(exception)情况:

SignInWithCredentialAsync encountered an error: System.AggregateException: Exception of type 'System.AggregateException' was thrown.
-----------------
Firebase.FirebaseException: An account already exists with the same email address but different sign-in credentials. Sign in using a provider associated with this email address.

UnityEngine.Debug:LogError(Object)
facebookLogin:<AuthCallback>m__0(Task`1) (at Assets/Script/facebookLogin.cs:82)
System.Threading.Tasks.TaskCompletionSource`1:SetException(AggregateException)
Firebase.Internal.TaskCompletionSourceCompat`1:SetExceptionInternal(TaskCompletionSource`1, AggregateException)
Firebase.Internal.TaskCompletionSourceCompat`1:SetException(TaskCompletionSource`1, AggregateException)
Firebase.Auth.FirebaseAuth:CompleteFirebaseUserTask(Task`1, TaskCompletionSource`1)
Firebase.Auth.<SignInWithCredentialAsync>c__AnonStorey4:<>m__0(Task`1)
System.Threading.Tasks.TaskCompletionSource`1:SetException(Exception)
Firebase.Auth.<GetTask>c__AnonStorey0:<>m__0()
Firebase.Auth.Future_User:SWIG_CompletionDispatcher(Int32)
Firebase.AppUtilPINVOKE:PollCallbacks()
Firebase.AppUtil:PollCallbacks()
Firebase.Platform.FirebaseAppUtils:PollCallbacks()
Firebase.Platform.FirebaseHandler:Update()
Firebase.Platform.FirebaseMonoBehaviour:Update()

我不知道哪里出了问题。 SignInWithCredentialAsync 似乎有问题,但我不知道如何解决。

最佳答案

我没有发现您的代码有任何问题。如错误所述,似乎有另一个帐户已经使用您尝试登录的 Facebook 帐户的电子邮件注册。您的应用是否允许其他登录方式?

来自 Firebase 帮助:

You can configure whether users can create multiple accounts that use the same email address, but are linked to different sign-in methods. For example, if you don't allow multiple accounts with the same email address, a user cannot create a new account that signs in using a Google Account with the email address ex@gmail.com if there already is an account that signs in using the email address ex@gmail.com and a password.

链接:https://support.google.com/firebase/answer/6400716?hl=en

您可以在 Firebase 控制台中修复此问题。在 Authentication > Sign-in Method 中,向下滚动,您将看到 “每个电子邮件地址多个帐户” 部分。允许它,错误应该被修复。

关于c# - 如何使用 Firebase 统一创建 Facebook 登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51407983/

50 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com