Sign In Register

How can we help you today?

Start a new topic
Answered

error: timeout when trying to login to facebook and get Leaderboards

 Hi, I follow the tutorials [1] on how to connect FB and create a leaderboard, everything works fine on Unity Editor and

 Test Harness, but when I build the APK and install my game on my phone, it stop working, I can't login to FB neither get the leaderboard, I put a Text to show me debug info and it says {"error": "timeout"}


This is my initial screen with a button to login to FB, the blue label at bottom of the screen shows me debug info.



When I click the button and give permissions to FB, it returns to the game screen and after 2 seconds, shows the error:




The same happens with the leaderboard, the green label at bottom show debug info:



after 5 seconds, shows the error:




This is the code I'm using to Login to FB:

 

public void Start ()
{
	txt_debug_fb.text = "ready to connect to FB";
}

public void LoginFBGameSparks ()
{
	if (!FB.IsInitialized) {
		FB.Init (FacebookLogin);
	} else {
		FacebookLogin ();
	}
}


public void FacebookLogin ()
{
	if (!FB.IsLoggedIn) {
		FB.Login ("", GameSparksLogin);
	} else {
		FB.Logout ();
		btn_login_fb_text.text = "FB Login";
		txt_debug_fb.text = "ready to connecto to FB";
	}
}

public void GameSparksLogin (FBResult result)
{
	if (FB.IsLoggedIn) {
		new FacebookConnectRequest ().SetAccessToken (FB.AccessToken).Send ((response) => {
			if (response.HasErrors) {
				txt_debug_fb.text = response.Errors.JSON;
			} else {
				btn_login_fb_text.text = "Logout";
				txt_debug_fb.text = "Connected to FB";
			}
		});
	}
}

 

 

and this is the code that shows the leaderboard:

public void GetLeaderboard ()
{
	txt_debug_log.text = "Getting Leaderboard...";
	new LeaderboardDataRequest_highScoreLeaderboard ().SetEntryCount (10).Send ((response) => {
		if (!response.HasErrors) {
			foreach (var entry in response.Data) {
				AddLeaderboardEntry (entry.Rank.ToString (),
			                     entry.UserName.ToString (),
			                     entry.GetNumberValue ("score").ToString ()
			        );
			}
		} else {
			txt_debug_log.text = response.Errors.JSON;
		}
	});
}

 

I would appreciate if someone can help me.


Thanks



[1]  https://www.youtube.com/watch?v=snz64n1Pa0s


Best Answer

Hi,

I added another button to login to facebook, with a simple callback and another button to login to facebook with Gamesparks callback, this is my code as I follow this tutorial https://docs.gamesparks.net/tutorials/unity-tutorial-logging-in-to-gamesparks-with-facebook : 

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

public class LoginWithGamesparks : MonoBehaviour
{
	public Text txtDebug;
	public Button btnLogout;

	public void StartLoginFBcallback ()
	{
		if (!FB.IsInitialized) {
			FB.Init (FacebookLoginFBcallback);
		} else {
			FacebookLoginFBcallback ();
		}
	}

	public void StartLoginGScallback ()
	{
		if (!FB.IsInitialized) {
			FB.Init (FacebookLoginGScallback);
		} else {
			FacebookLoginGScallback ();
		}
	}
	
	void FacebookLoginFBcallback ()
	{
		Debug.Log ("Simple FB callback");
		if (!FB.IsLoggedIn) {
			FB.Login ("email", FBLoginCallBack);
		} else {
			OnLoggedIn ("FBcallback");
		}
	}
	void FacebookLoginGScallback ()
	{
		Debug.Log ("Gamesparks callback");
		if (!FB.IsLoggedIn) {
			FB.Login ("email", GamesparksCallback);
		} else {
			OnLoggedIn ("GScallback");
		}
	}
	void FBLoginCallBack (FBResult result)
	{
		txtDebug.text = "simple Callback";
		if (FB.IsLoggedIn) {
			OnLoggedIn ("FBcallback");
		}
	}

	void GamesparksCallback (FBResult result)
	{
		if (FB.IsLoggedIn) {
			new FacebookConnectRequest ().SetAccessToken (FB.AccessToken).Send ((response) =>
			{
				if (response.HasErrors) {
					Debug.Log ("Something failed with connecting with Facebook");
					txtDebug.text = response.Errors.JSON;
				} else {
					OnLoggedIn ("GScallback");
				}
			});
		}
	}

	void OnLoggedIn (string whichCallback)
	{
		txtDebug.text = "Logged in : " + FB.UserId + " with " + whichCallback;
		btnLogout.gameObject.SetActive (true);
	}
	
	public void FBLogout ()
	{
		FB.Logout ();
		txtDebug.text = "Logged out";
		btnLogout.gameObject.SetActive (false);
	}
	
}


and these are screenshots running my game in Unity Editor and clicking on each button to test them:


1: menu screen with the 2 buttons to test the FB Login feature


 

2. First I clicked on the first button, that uses a simple FB callback (StartLoginFBcallback)

and it's successfully logged into facebook so, my game can talk to FB with no problems


3. I logged out

Successfully logged out


4. now use the 2nd button to try to login with Gamesparks callback (StartLoginGScallback)

and it's successfully logged into facebook, so it seems to work good con Unity Editor.




Now I try to do the same with the game installed on a device:


1. Screen with the 2 buttons



2. Successfully logged in with the first button, with the simple Callback: 

So yes, my game can talk to FB when it's installed on the device. 



3. Logged out and now try to Login with the 2nd button, with GameSparks callback

But I got that  {"error": "timeout"} 



and this is the output using  ./monitor



I have a snapshot published in GameSparks' dashboard, so I can't figure out why I can't login into Facebook using the GameSparks callback.

I followed the tutorial, but nothing seems to work when the game is installed in device :( 





1 person has this question

I figured that what is causing the error is the Stripping Level con Unity Player Settings, when it's set to None, it works on device, but when Stripping Level is set to one of the options, it stop working on device, so I find this thread https://support.gamesparks.net/support/discussions/topics/1000032278 and create the file link.xml and now it works again on device with Stripping Level set.

It stopped working again, it was working yesterday and I did not touch that part of the code, and now I get that Timeout error again... this is frustrating...

That's what I did, create a new project from scratch, new GameSparks dashboard and new Facebook App and now it works.

It´s so strange because I did the same steps once and then but in the first attempt it didn't work.

Have you made a repro project which isolates that the issue is related to GameSparks on an Android device?


If so can you send a download link to this project, and I'll be happy to help see where the issue is.


Otherwise I would suggest trying a new simple project from scratch, and seeing if the issue still exists. Perhaps even try a new GameSparks game ID.

Answer

Hi,

I added another button to login to facebook, with a simple callback and another button to login to facebook with Gamesparks callback, this is my code as I follow this tutorial https://docs.gamesparks.net/tutorials/unity-tutorial-logging-in-to-gamesparks-with-facebook : 

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

public class LoginWithGamesparks : MonoBehaviour
{
	public Text txtDebug;
	public Button btnLogout;

	public void StartLoginFBcallback ()
	{
		if (!FB.IsInitialized) {
			FB.Init (FacebookLoginFBcallback);
		} else {
			FacebookLoginFBcallback ();
		}
	}

	public void StartLoginGScallback ()
	{
		if (!FB.IsInitialized) {
			FB.Init (FacebookLoginGScallback);
		} else {
			FacebookLoginGScallback ();
		}
	}
	
	void FacebookLoginFBcallback ()
	{
		Debug.Log ("Simple FB callback");
		if (!FB.IsLoggedIn) {
			FB.Login ("email", FBLoginCallBack);
		} else {
			OnLoggedIn ("FBcallback");
		}
	}
	void FacebookLoginGScallback ()
	{
		Debug.Log ("Gamesparks callback");
		if (!FB.IsLoggedIn) {
			FB.Login ("email", GamesparksCallback);
		} else {
			OnLoggedIn ("GScallback");
		}
	}
	void FBLoginCallBack (FBResult result)
	{
		txtDebug.text = "simple Callback";
		if (FB.IsLoggedIn) {
			OnLoggedIn ("FBcallback");
		}
	}

	void GamesparksCallback (FBResult result)
	{
		if (FB.IsLoggedIn) {
			new FacebookConnectRequest ().SetAccessToken (FB.AccessToken).Send ((response) =>
			{
				if (response.HasErrors) {
					Debug.Log ("Something failed with connecting with Facebook");
					txtDebug.text = response.Errors.JSON;
				} else {
					OnLoggedIn ("GScallback");
				}
			});
		}
	}

	void OnLoggedIn (string whichCallback)
	{
		txtDebug.text = "Logged in : " + FB.UserId + " with " + whichCallback;
		btnLogout.gameObject.SetActive (true);
	}
	
	public void FBLogout ()
	{
		FB.Logout ();
		txtDebug.text = "Logged out";
		btnLogout.gameObject.SetActive (false);
	}
	
}


and these are screenshots running my game in Unity Editor and clicking on each button to test them:


1: menu screen with the 2 buttons to test the FB Login feature


 

2. First I clicked on the first button, that uses a simple FB callback (StartLoginFBcallback)

and it's successfully logged into facebook so, my game can talk to FB with no problems


3. I logged out

Successfully logged out


4. now use the 2nd button to try to login with Gamesparks callback (StartLoginGScallback)

and it's successfully logged into facebook, so it seems to work good con Unity Editor.




Now I try to do the same with the game installed on a device:


1. Screen with the 2 buttons



2. Successfully logged in with the first button, with the simple Callback: 

So yes, my game can talk to FB when it's installed on the device. 



3. Logged out and now try to Login with the 2nd button, with GameSparks callback

But I got that  {"error": "timeout"} 



and this is the output using  ./monitor



I have a snapshot published in GameSparks' dashboard, so I can't figure out why I can't login into Facebook using the GameSparks callback.

I followed the tutorial, but nothing seems to work when the game is installed in device :( 




What does your logging say? Are you logging using monitor.bat to see what is causing the problem?

Yes, my device in online, this is so strange.

I tried using another backend and it logged in to FB, but that other backend doesn't have some features I need that GameSparks has, but unfortunately I can't have GameSparks working on my game when the APK is generated, everything works fine in Unity Editor but not in device.

I have all Key Hashes, I have a snapshot published in GameSparks dashboard; in theory I have everything needed to make it works, but it doesn't work... 

It works for me, I've just been through the tutorial. 


Was your device online? i.e connected to the internet?


I had no problems getting this working, so you're definately doing something wrong in the config/setup.

Hi


Yes I had all the key hashes generated and set on facebook dashboard, but my game couldn't make a facebook login when installed on a device, just on Unity Editor.

Sadly I have to switch to another solution, btw thanks for your reply.


P.D. I'm not using Windows, but thanks for your advice.

Hi Mostro, 


Did you generate the Android key hashes? These are required for connecting a device to Facebook.
Read more here.. under the Running Sample Apps heading...
https://developers.facebook.com/docs/android/getting-started#create-app

Read more here about the issue
http://stackoverflow.com/questions/27468813/this-app-has-no-android-key-hashes-configured-login-with-facebook-sdk

I would also suggest using the Android monitor.bat utility to log the output of your device so you can get better information on the errors you are having.
Run the logger by double clicking the file <AndroidSDKFolder>\tools\monitor.bat