What’s the difference between Facebook SDK Unity and Parse Unity SDK ?
Is it need to implement both SDK if I want to use Facebook Login and save game data from mobile game?
I am beginner in integrate my mobile game with Facebook. I am confused that both SDK need implement in Unity or just one of them if I want use Facebook Ligin and save game score of mobile game? Thank you.
You do actually need both, it’s true. it’s quite confusing.
get the facebook plugin here,
and you know where to get the parse one, on parse.com
Here’s some general code with A LOT OF COMMENTS, I encourage to read the comments carefully
Sorry it doesn’t fit the line width here, be sure to scroll left-right to read.
// general note:
// you might think there'd be a command on Parse "let user login with FB, and then connect to Parse"
// however that is not the case. you have to have the user login to FB (just as you would if
// your app had nothing to do with Parse). And then afterwards, simply call to Parse "LogInAsync".
// so use Facebook's Unity 'Login' command. here's the source doco
// https://developers.facebook.com/docs/unity/reference/current/FB.Login
FB.Login("friends_about_me, email", _callbackFBLogin);
private void _cbFBLogin(FBResult result)
{
Debug.Log("_fbLogin result.Text ... " +result.Text);
Debug.Log("_fbLogin result.Error ... " +result.Error);
// the best way to test for error conditions here is simply to check if, indeed,
// the user is now logged in.
if( FB.IsLoggedIn )
FBLoginOKNowParseLogin();
else
.. something like "couldn't log in, try later"
}
private void FBLoginOKNowParseLogin()
{
StartCoroutine( _FBToParse() );
}
private IEnumerator _FBToParse()
{
Debug.Log("FB user: FB.UserId FB.AccessToken " +FB.UserId +" " +FB.AccessToken);
// general note:
// you might think there'd be a command on Parse "let user login with FB, and then connect to Parse"
// however that is not the case. you have to have the user login to FB (just as you would if
// your app had nothing to do with Parse). And then afterwards, simply call to Parse "LogInAsync".
// so your user is now completely logged-in with FB. So call LogInAsync at Parse..
Task<ParseUser> linkTask = ParseFacebookUtils.LogInAsync(
FB.UserId,
FB.AccessToken,
DateTime.Now
);
// note. it seems to be the case that DateTime.Now works best
// some example code shows, adding one hour or one day to the current time.
// simply using DateTime.Now seems to work best.
// probably bring up a spinner here while it's connecting
while ( !linkTask.IsCompleted ) yield return null;
if ( linkTask.IsFaulted || linkTask.IsCanceled )
{
... couldn't reach parse
yield break;
}
ParseUser newOrOldUser = (ParseUser)linkTask.Result;
... and so on ..... !
You don’t need parse if your application doesn’t want to save/create session for your user . Parse is one of the easiest way to implement this especially if u wanna manage your session etc. Parse also have capability do analytic on your user behaviour which is common for application that logged people in.