Sign In Register

How can we help you today?

Start a new topic
Answered

create profile without facebook Unity

Hey there,


In one of the Unity leaderboard tutorials it said that you could create a user without using facebook but I can't find any info on how to do this. 


What I have tried is the following in the hope that I can have the option of either logging in with facebook or create profile but it doesnt seem to be working. Any ideas?

 

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

public class APIManager : MonoBehaviour {

	string playerName;
	public GameObject connectionErrorPopup;

	public StartPanel startPanel;
	

	public void StartLogin()
	{

		playerName = PlayerPrefs.GetString("PlayerName");


		if(string.IsNullOrEmpty(playerName))
		{
			// ** Post error here **
			Debug.Log ("Please enter username");
		}

		else
		{
			//GameSparkLogin
			GameSparksLogin(playerName);
		}
	}

	
	// Use this for initialization if using FB
	public void StartFBLogin () {
		//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("", GameSparksLoginFB);
		}
	}
	
	//GameSparksLogin takes FBResult from FB.Login but we don't use it 
	//for anything
	public void GameSparksLoginFB(FBResult result) 
	{
		//It never hurts to double check it you are logged into Facebook                
		//before trying to log into GameSparks with Facebook
		if (FB.IsLoggedIn)
		{
			//This is the standard FacebookConnectRequest. This will                        
			//log into GameSparks with your Facebook Profile.
			new FacebookConnectRequest().SetAccessToken(FB.AccessToken).Send((response) =>
			                                                                 {
				if (response.HasErrors)
				{
					Debug.Log("Something failed with connecting with Facebook");

					//** SHOW ERROR POPUP HERE**
				}
				else
				{
					//Here you can display some information                                                                             
					//to the user that they are logged in...

					//Hide start panel
					startPanel.HidePanel();
				}
			});
		}
	}

	public void GameSparksLogin(string name)
	{
		//**Send profile name if no facebook**
		new RegistrationRequest().SetDisplayName(name).Send((response) =>
		                                                    {
			if (response.HasErrors)
			{
				Debug.Log("Something failed with connecting with Username");
				
				//** SHOW ERROR POPUP HERE**
			}
			else
			{
				//Here you can display some information                                                                             
				//to the user that they are logged in...
				
				//Hide start panel
				startPanel.HidePanel();
			}
		});
	}
}

 


Best Answer

Hi Will,


What version of Unity and the SDK are you using? What platform are you targeting?


To create a profile without Facebook with a RegistraionRequest which will require your users to supply a username, displayName and password, or you could use a DeviceAuthenticationRequest which will register them anonymously. Please note that currently there is no default way to convert a DeviceAuthenticated user to a registered user.


It's best to do these requests after making sure GameSparks has loaded, for instance, if you put GameSparks in a "Splash Screen" loader type scene, then register the user once, the main menu comes up. Otherwise you'll get errors saying GameSparks cant be reached.


Shane


I notice in the console I get this: GS: RECV:{"@class":".RegistrationResponse","error":{"userName":"REQUIRED","password":"REQUIRED"},"requestId":"635592478908673840_0","scriptData":null}


So I can see I need to add userName and password. I will probably make username same as display name but what is the purpose of password and how would I generate it? I don't want to have the user input one as its not very useful to them

Reverted my changes on the above script and unity is no longer crashing. 


I just need to know how to give my players the option to either login with facebook or to create a profile. If someone knows how to do this please let me know

I take that back. Still getting the too many threads in GC unity crash even with the changes reverted to the tutorial script

Answer

Hi Will,


What version of Unity and the SDK are you using? What platform are you targeting?


To create a profile without Facebook with a RegistraionRequest which will require your users to supply a username, displayName and password, or you could use a DeviceAuthenticationRequest which will register them anonymously. Please note that currently there is no default way to convert a DeviceAuthenticated user to a registered user.


It's best to do these requests after making sure GameSparks has loaded, for instance, if you put GameSparks in a "Splash Screen" loader type scene, then register the user once, the main menu comes up. Otherwise you'll get errors saying GameSparks cant be reached.


Shane

Login to post a comment