- Home /
Question by
sonukrshah · Dec 08, 2021 at 03:07 PM ·
facebooklogin
Facebook Unity SDK Auto Login not works?
When I open my game first time on android then Facebook login works fine but when I re-open the game I have to re-login every time. I don't want this, I want it to login itself once I login.
Here the code:
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());
}
}
Comment
Your answer
Follow this Question
Related Questions
facebook login on android 0 Answers
How to setup SDK-less Social Login using Application.OpenURL 0 Answers
How to get facebook login pop in my unity project? 0 Answers
unishare help!!!! 1 Answer
Facebook Login " Invalid App Id : 0 " 0 Answers