I'm developing "Log in with Facebook" support in my game with the official Unity Facebook SDK. Actually I'm using the beta version 6.1 (but this problem where also in the stable version, 6.0).
A user can log in successfully and then I can make FB api requests. The problem is that FB SDK isn't saving the session, since when you close the app and launch it again, the FB.IsLoggedIn
value is false
.
It doesn't work in any platform: Editor, iOS & Android.
Note: The Status
property in Facebook Settings is already checked.
Here's how I implemented it:
FacebookController.cs
void Awake()
{
if (instance == null)
{
DontDestroyOnLoad(gameObject);
instance = this;
FB.Init(OnFacebookInit);
} else if (instance != this)
{
Destroy(gameObject);
}
}
void OnFacebookInit()
{
if (FB.IsLoggedIn)
{
FBIsLoggedIn();
}
}
public void LoginWithFacebook(OnUserAuthenticated _userAuthCallback)
{
userAuthCallback = _userAuthCallback;
FB.Login("email, user_friends", AuthCallback);
}
void AuthCallback(FBResult result)
{
if (FB.IsLoggedIn)
{
FBIsLoggedIn();
} else
{
Debug.Log("User cancelled login");
}
}
void FBIsLoggedIn()
{
FB.API("me", Facebook.HttpMethod.GET, UserCallBack);
FB.API("me/friends", Facebook.HttpMethod.GET, FriendsCallback);
}
Do I need to add some code to make FB save the valid session?
Thanks in advance!
UserCallback
method. – Arol