Facebook Unity SDK自动登录不起作用



我使用unity3D,当我第一次在android上打开游戏时,Facebook登录效果很好,但当我重新打开游戏时,我每次都必须重新登录。我不想要这个,我希望它在我登录后自行登录

这里的代码:

public class FaceBook : MonoBehaviour
{
public Text FB_userName;
public Image FB_userDp;
void Start()
{
FB.Init(InitCallback);
}
void InitCallback()
{
if (FB.IsInitialized)
{
FBLogin();
}
else
{
Debug.Log("Failed to Initialize the Facebook SDK");
}
}
void FBLogin()
{
List<string> perms = new List<string>() { "gaming_user_picture" };
FB.LogInWithReadPermissions(perms, AuthCallback);
}
void AuthCallback(ILoginResult result)
{
if (FB.IsLoggedIn)
{
FB.API("/me?fields=first_name", HttpMethod.GET, DisplayUsername);
FB.API("/me/picture?type=med", HttpMethod.GET, DisplayProfilePic);
}
}
void DisplayUsername(IResult result)
{
string name = "" + result.ResultDictionary["first_name"];
FB_userName.text = name;
}
void DisplayProfilePic(IGraphResult result)
{
FB_userDp.sprite = Sprite.Create(result.Texture, new Rect(0, 0, result.Texture.width, result.Texture.height), new Vector2());
}
}

您只需检查FB.IsLoggedIn,只有在用户未登录时才会提示用户

最新更新