We're working on a game that is supposed to be served on the Facebook canvas (WebGL build). We're using Unity 5.2 and Facebook SDK 7.2.0.
After the recent SDK release, we're having troubles with logins in both web and webGL builds.
The game is supposed to log you in right from the start through FB.LogInWithReadPermissions(r_permissions, AuthCallback);
but the callback gets stuck while ILoginResult (the result of a login request) is looking for the "grantedScopes" parameter.
void AuthCallback(ILoginResult r)
{
if (!string.IsNullOrEmpty(r.Error))
{
Debug.LogError("OnFBConnected: failed");
return;
}
if (FB.IsLoggedIn)
{
OnFBConnected();
}
else
{
Debug.LogWarning("User cancelled facebook login.");
}
}
The code we implemented seems correct, so the problem may lie inside the SDK's scripts (LoginResult.cs in particular). We have already checked for the Json file that you receive in the callback from the fb canvas and it has no grantedScopes
field.
this is the warning log from the unity console:
Failed to find parameter 'grantedScopes' in login result:
UnityEngine.Debug:LogWarning(Object)
Facebook.Unity.CustomLogger:Warn(String)
Facebook.Unity.FacebookLogger:Warn(String)
Facebook.Unity.FacebookLogger:Warn(String, String[])
Facebook.Unity.LoginResult:ParsePermissionFromResult(IDictionary`2)
Facebook.Unity.LoginResult:ParseAccessTokenFromResult(IDictionary`2)
Facebook.Unity.LoginResult:.ctor(String)
Facebook.Unity.Canvas.CanvasFacebook:OnLoginComplete(String)
Facebook.Unity.FacebookBase:OnInitComplete(String)
Facebook.Unity.FacebookGameObject:OnInitComplete(String)
Facebook.Unity.Canvas.JsBridge:OnInitComplete(String)
anybody had this problem before?
I was working with Mastocobra on this and we figured out the problem:
Facebook will not return the granted scopes if there are no new permissions to be granted. After the first time that the user logs in and grants the permission, there will be an AccessToken with the available permissions reserved already, so instead of asking for the permissions again or waiting for the callback, you just check if the user is already logged in and use the information from the AccessToken that is already there.
The overall flow of the code is something like this:
void Start(){
if(!FB.IsInitialized){
FB.Init(OnInit)
} else {
OnInit()
}
}
void OnInit(){
if(!FB.IsInitialized) Debug.LogError("Failed to Initialize");
if(!FB.IsLoggedIn){
FB.LogInWithReadPermissions(mPermissions, AuthCallback);
} else {
OnFBConnected();
}
}
void AuthCallback(ILoginResult r)
{
if (!string.IsNullOrEmpty(r.Error))
{
Debug.LogError("OnFBConnected: failed");
return;
}
if (FB.IsLoggedIn)
{
OnFBConnected();
}
else
{
Debug.LogWarning("User cancelled facebook login.");
}
}
void OnFBConnected(){
//Do whatever you need with the AccessToken you have
}
Before the transition to the new Facebook SDK that supports Unity 5, anytime you would try to log in, it would return you all the permissions available, even if you had already logged in before. For at least one of the last 3 releases, this seemed to be true for the Android version, so it definitelly threw us off of our game as we were trying to pinpoint the issue.
TL;DR: Don't expect a callback for logging in if you had already logged in once.