I am trying to enable leaderboards in my Unity game and have no server available to store data in a database. I’m new to this whole thing but have seen tutorials for GameSpark and Facebook leaderboard integration. Is this the best/most efficient way to implement leaderboards for free into unity android games?
Hrm everything works in unity editor on pc. I connect up using the mock login dialog from Facebook sdk, and then post score and then get the top 10 scores on leaderboard. However when I compile for android, I get no login dialog and the leaderboard is empty… Any ideas?
1.) Install latest version of Facebook on your Android device
2.) Make sure Android is added as a platform in your Facebook App
3.) Setup the device hash in the Facebook app with your device ID
4.) When running your app on Android, it should successfully ask if you want to add this app to Facebook, if there are errors, it will have something to do with your Android/Facebook App setup.
There is a lot of posts on how to do all the above, so Google around.
And yes I do agree with you, GameSparks is awesome, and we are using it in our game
Doesn’t seem to be showing me alogin screen. I’ve peppered the game with debug Text instantiations to help me follow the connection process on Android (which 100% works on PC in editor), and the text stops showing at “FB Not Logged in, Logging In”, whereas in editor it shows me all 4 messages… Not sure whats going on heres my code. Also GameSparks is in preview mode but I think this is OK:
using UnityEngine;
using System.Collections;
using Facebook.Unity;
using Facebook;
using GameSparks.Api.Requests;
using System.Collections.Generic;
using UnityEngine.UI;
public class LoginManager : MonoBehaviour {
public Text _textPrefab;
private Canvas _canvas;
// Use this for initialization
void Awake () {
_canvas = GameObject.FindGameObjectWithTag("Canvas").GetComponent<Canvas>();
//If facebook is not Initialized
if (!FB.IsInitialized)
{
//Call FB.Init and once that's complete we'll call
//Facebook Login
FB.Init(FacebookLogin);
}
//Otherwise if we already initialized call Facebook Login
else
{
FacebookLogin();
}
}
public void FacebookLogin()
{
//If we aren't logged in
if (!FB.IsLoggedIn)
{
Text successText = Instantiate(_textPrefab, new Vector3(-300f, 300f, 0f), Quaternion.identity) as Text;
successText.text = "FB Not Logged in, Logging In";
successText.GetComponent<RectTransform>().offsetMax = new Vector2(0f, 200f);
successText.GetComponent<RectTransform>().offsetMin = new Vector2(0f, 200f);
successText.transform.SetParent(_canvas.transform);
//Call FB.Login, tell it to call GameSparksLogin
//when done
FB.LogInWithReadPermissions(new List<string>() {"email"}, GameSparksLogin);
}
}
//GameSparksLogin takes FBResult from FB.Login but we don't use it
//for anything
public void GameSparksLogin(ILoginResult result)
{
Text successText4 = Instantiate(_textPrefab, new Vector3(-300f, 300f, 0f), Quaternion.identity) as Text;
successText4.text = "Gamespark logging in begging.";
successText4.GetComponent<RectTransform>().offsetMax = new Vector2(0f, 200f);
successText4.GetComponent<RectTransform>().offsetMin = new Vector2(0f, 200f);
successText4.transform.SetParent(_canvas.transform);
//It never hurts to double check it you are logged into Facebook
//before trying to log into GameSparks with Facebook
if (FB.IsLoggedIn)
{
Text successText2 = Instantiate(_textPrefab, new Vector3(-300f, 300f, 0f), Quaternion.identity) as Text;
successText2.text = "FB Logged in, Logging Into GameSparks";
successText2.GetComponent<RectTransform>().offsetMax = new Vector2(0f, 200f);
successText2.GetComponent<RectTransform>().offsetMin = new Vector2(0f, 200f);
successText2.transform.SetParent(_canvas.transform);
//This is the standard FacebookConnectRequest. This will
//log into GameSparks with your Facebook Profile.
new FacebookConnectRequest().SetAccessToken(AccessToken.CurrentAccessToken.TokenString).Send((response) =>
{
if (response.HasErrors)
{
Text failText = Instantiate(_textPrefab, new Vector3(0f, 0f, 0f), Quaternion.identity) as Text;
failText.text = "Failed Facebook Login";
failText.GetComponent<RectTransform>().offsetMax = new Vector2(0f, 200f);
failText.GetComponent<RectTransform>().offsetMin = new Vector2(0f, 200f);
failText.transform.SetParent(_canvas.transform);
Debug.Log("Something failed with connecting with Facebook");
}
else
{
Text successText3= Instantiate(_textPrefab, new Vector3(-300f, 300f, 0f), Quaternion.identity) as Text;
successText3.text = "Succesfully logged into Facebook!!!!!!!!!!!";
successText3.GetComponent<RectTransform>().offsetMax = new Vector2(0f, 200f);
successText3.GetComponent<RectTransform>().offsetMin = new Vector2(0f, 200f);
successText3.transform.SetParent(_canvas.transform);
Debug.Log("Successfully logged into facebook");
}
});
}
}
}
OK I went through the process of installing javasdk, opens and copying bin filed from openssl to jdk bin, running the key store openssl command in prompt, then there was a hash key I put into Facebook and put class name and bundle id. So excited I compiled to phone anddddd! Nothing. Didn’t work?
I tried to regenerate android manifest and there’s an error …/Assets\Plugins/ is not found… I don’t know why there’s a back slash in a file directory path and why when I imported the Facebook sdk it didn’t create the wrong folders, but I will try to Uninstaller and reinstall the Facebook sdk
I’m great I got it! Thanks for all your help, for some reason my facebook+gamesparks imported packages were not imported correct. I removed and re-added and rebuilt android manifest + generated the hash and now it’s working thanks. I need to donate money to gamesparks.