Sign In Register

How can we help you today?

Start a new topic
Answered

How do you post to leaderboard without facebook

After alot of messing about i finally got the application to work with the leader board from Facebook on my mobiles etc. Taking users information to post a high score on gamesparks i was wondering if there is a way to do this so that i dont use facebook to post the scores. as some of my users do not have facebook. 


I have it all setup going from the videos that game sparks provided and my environment works. Any help would be fantastic (or if someone could link a tutorial) thanks alot !. 


Best Answer

Sure ... You can use the following to Authenticate (using the other methods greg alluded to above) ...


 

using UnityEngine;
using System.Collections;
using GameSparks.Api.Requests;
using GameSparks.Api.Responses;
using GameSparks.Core;

public class LoginController : MonoBehaviour { 

	void LoginDeviceAuthentication () {
		AuthenticationResponse authResponse = new DeviceAuthenticationRequest ().Send ();

		if (authResponse.HasErrors) {
			Debug.Log("Device Authentication failed ...");
		} else {
			Debug.Log("Device Authentication suceeded ...");
		}
	}

	void RegisterUser (string userName, string password, string displayName) {
		
		Debug.Log ("Calling register user ... ");

		RegistrationResponse regResponse = new RegistrationRequest ().SetUserName (userName). SetPassword (password) .SetDisplayName (displayName) .Send ();
		
		if (regResponse.HasErrors) {
			Debug.Log ("Registration failed ...");
		} else {
			Debug.Log ("Registration succeeded ..." + regResponse);
		}

	}

	void AuthenticateUser (string userName, string password) {
		
		Debug.Log ("Authenticating user ... ");
		
		AuthenticationResponse authResponse = new AuthenticationRequest ().SetUserName (userName). SetPassword (password) .Send ();
		
		if (authResponse.HasErrors) {
			Debug.Log ("Registration failed ...");
		} else {
			Debug.Log ("Registration succeeded ..." + authResponse);
		}
	}

}

 

Then to post a score to a leaderboard, you can do the following:


 

void PostScore (int myScore) {
		
		LogEventResponse logEvtResponse = new LogEventRequest ().SetEventKey ("PostScore").SetEventAttribute ("SCORE", myScore) .Send ();
		
		if (logEvtResponse.HasErrors) {
			Debug.Log("Post score failed ...");
		} else {
			Debug.Log("Post score succeeded ..." + logEvtResponse);
		}
	}

 

Rgds



Hi James,


In the GameSparks service request API, you are not only limited to Facebook authentication requests, but various other providers are available to.

This page in the docs shows you the various authentication requests you can make (click on the Authentication tab), as you can see you have FacebookConnectRequest, but you can use any of the other methods posted there.

Im abit of a noob with this. Is there any guides available to help me understand the coding behind it like my facebook login is like. 


 

using UnityEngine;
using System.Collections;
using Facebook;
using GameSparks.Api.Requests;

public class LoginManager : MonoBehaviour {
	
	// Use this for initialization
	/*void Awake () {
		//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 fbloggin () {

		if (PlayerPrefs.GetString ("SuperHornet") == "") {
			PlayerPrefs.SetString ("SuperHornet", "YesS");
		} else {
			PlayerPrefs.SetString ("SuperHornet", "");
		}

		//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)
		{
			//Call FB.Login, tell it to call GameSparksLogin
			//when done
			FB.Login("", GameSparksLogin);
		}
	}
	public void GameSparksLogin(FBResult result)
	{
		if (FB.IsLoggedIn)
		{
			new FacebookConnectRequest().SetAccessToken(FB.AccessToken).Send((response) =>
			    {
					if(response.HasErrors)
				{
					Debug.Log ("Something failed when connecting with facebook");
				} else {
					Debug.Log ("GameSparks Facebook Login successful");
				}
			});

		}
	}
}

 what would the GameSparks version look like where they enter a username to upload there score ? cheers if you can help ill keep looking into it and thanks for that page. any help would be greatly appreciated 

Answer

Sure ... You can use the following to Authenticate (using the other methods greg alluded to above) ...


 

using UnityEngine;
using System.Collections;
using GameSparks.Api.Requests;
using GameSparks.Api.Responses;
using GameSparks.Core;

public class LoginController : MonoBehaviour { 

	void LoginDeviceAuthentication () {
		AuthenticationResponse authResponse = new DeviceAuthenticationRequest ().Send ();

		if (authResponse.HasErrors) {
			Debug.Log("Device Authentication failed ...");
		} else {
			Debug.Log("Device Authentication suceeded ...");
		}
	}

	void RegisterUser (string userName, string password, string displayName) {
		
		Debug.Log ("Calling register user ... ");

		RegistrationResponse regResponse = new RegistrationRequest ().SetUserName (userName). SetPassword (password) .SetDisplayName (displayName) .Send ();
		
		if (regResponse.HasErrors) {
			Debug.Log ("Registration failed ...");
		} else {
			Debug.Log ("Registration succeeded ..." + regResponse);
		}

	}

	void AuthenticateUser (string userName, string password) {
		
		Debug.Log ("Authenticating user ... ");
		
		AuthenticationResponse authResponse = new AuthenticationRequest ().SetUserName (userName). SetPassword (password) .Send ();
		
		if (authResponse.HasErrors) {
			Debug.Log ("Registration failed ...");
		} else {
			Debug.Log ("Registration succeeded ..." + authResponse);
		}
	}

}

 

Then to post a score to a leaderboard, you can do the following:


 

void PostScore (int myScore) {
		
		LogEventResponse logEvtResponse = new LogEventRequest ().SetEventKey ("PostScore").SetEventAttribute ("SCORE", myScore) .Send ();
		
		if (logEvtResponse.HasErrors) {
			Debug.Log("Post score failed ...");
		} else {
			Debug.Log("Post score succeeded ..." + logEvtResponse);
		}
	}

 

Rgds


Login to post a comment