I use unity3D, 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());
}
}
You just check FB.IsLoggedIn and only prompt the user if they are not logged in
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.