如何从Facebook注销并切换用户?

时间:2018-10-25 20:33:07

标签: c# facebook authentication unity3d facebook-unity-sdk

我与用户一起在我的应用程序上登录了Facebook。

以后,当我在Facebook应用程序和浏览器上手动注销该用户时,

(FB.IsLoggedIn)仍返回true。 由于某些原因,旧的个人资料已保存,我无法使用新用户登录

这是我的代码:

public void FacebookLogin()
{
    if (FB.IsLoggedIn)
        FB.LogOut();  //it doesn't work, user is still logged in


     var permissions = new List<string>() {"email"};
      FB.LogInWithReadPermissions(permissions);  //trying to login a new user, but the last user is still logged in

2 个答案:

答案 0 :(得分:0)

FacebookLogin函数更改为协程函数。这样,您可以检查用户是否登录,注销该用户,然后等待每一帧,直到FB.IsLoggedInfalse为止,然后才能登录另一个用户。还要在等待中添加一个计时器,这样当FB.IsLoggedIn时间内false从未x时,该函数将不会继续运行,但会显示一些错误并退出。

public IEnumerator FacebookLogin()
{
    //5 seconds loggout time
    float waitTimeOut = 5f;

    //Log out if loggedin
    if (FB.IsLoggedIn)
        FB.LogOut();  //it doesn't work, user is still logged in

    //Wait until logout is done. Also add a timeout to the wait so that it doesnt wait forever
    float timer = 0;
    while (FB.IsLoggedIn)
    {
        if (timer > waitTimeOut)
        {
            Debug.LogError("Failed to log out within " + waitTimeOut + " seconds");
            yield break;
        }
        timer += Time.deltaTime;
        yield return null;
    }
    Debug.Log("Successfully logged out. Now logging another user in");
    var permissions = new List<string>() { "email" };
    FB.LogInWithReadPermissions(permissions);  //trying
}

如果您仍然对此有疑问,则需要在facebook-sdk-for-unity Github页面上使用此答案中的代码提交错误报告。

答案 1 :(得分:0)

您要在注销后登录。

F:\SampleTraining\negdata\0.jpg
F:\SampleTraining\negdata\1.jpg
F:\SampleTraining\negdata\2.jpg
...
F:\SampleTraining\negdata\958.jpg