Why does the Android Express Login for Facebook never work?

Hello,

I hope very very much please please anyone can help me …

I become very much crazy with this Facebook SDK, I hate the Facebook SDK …

I’m developing a game for Android, iOS and Windows using Unity3D, Android is the focus for now.

I installed the latest Facebook Unity SDK 14.1.0 and I’ve already spent 2 weeks getting the normal Facebook login to work because my app kept crashing after pressing the Facebook button. But now it’s finally working…

I just can’t get the express login to work at all.

I’ve been reading on the internet for days, tried so many things, it just doesn’t work…

I use this code as described 1000 times on the internet and in the Facebook developer documentation, but it just doesn’t work on the Android smartphone…

FB.Android.RetrieveLoginStatus(LoginStatusCallback);

private void LoginStatusCallback(ILoginStatusResult result)
{
      if (!string.IsNullOrEmpty(result.Error))
      {
        Debug.Log("Error: " + result.Error);
      }
      else if (result.Failed)
      {
      // !!! This result always comes :-(((  !!!

      Debug.Log("Failure: Access Token could not be retrieved");
      }
      else
      {
        // Successfully logged user in
        // A popup notification will appear that says
        // "Logged in as <User Name>"

     
        // !!! This result never comes, but it should come after I restart the app and I have
        // successfully logged in before. !!!

        Debug.Log("Success: " + result.AccessToken.UserId);
      }
}

And this is my AndroidManifest.xml …

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.unity3d.player" android:installLocation="preferExternal" android:versionCode="1" android:versionName="1.0">
    <queries>
        <package android:name="com.facebook.katana" />
    </queries>
    <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
    <application android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false" android:allowBackup="false" android:fullBackupContent="false">
    <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>
    <receiver android:name="com.xxxxxxxxxxxxxx.SmsReceiver.SmsListener" android:enabled="true" android:exported="true">
      <intent-filter>
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
      </intent-filter>
    </receiver>
    <activity android:name="com.facebook.unity.FBUnityLoginActivity" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
    <activity android:name="com.facebook.unity.FBUnityDialogsActivity" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
    <activity android:name="com.facebook.unity.FBUnityGamingServicesFriendFinderActivity" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
    <activity android:name="com.facebook.unity.FBUnityAppLinkActivity" android:exported="true" />
    <activity android:name="com.facebook.unity.FBUnityDeepLinkingActivity" android:exported="true" />
    <activity android:name="com.facebook.unity.FBUnityGameRequestActivity" />
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="fbxxxxxxxxxxxxxxxxxxxx" />
    <meta-data android:name="com.facebook.sdk.ClientToken" android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
    <meta-data android:name="com.facebook.sdk.AutoLogAppEventsEnabled" android:value="true" />
    <meta-data android:name="com.facebook.sdk.AdvertiserIDCollectionEnabled" android:value="true" />
    <provider android:name="com.facebook.FacebookContentProvider" android:authorities="com.facebook.app.FacebookContentProviderxxxxxxxxxxxxxxxxxxxx" android:exported="true" />
    </application>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />
</manifest>

Minimum API level: 29 → Target API level: 32
I use also Amazon AWS with various services in my project.

All the Amazon AWS API’s is much more demanding and complex than the Facebook API, but strange thanks to excellent documentation I have absolutely no problems with it and everything just works except Facebook…

I just want the player to log in to my game app with Facebook once and when the app is restarted there shouldn’t be a message or anything, just silently log in with Facebook until the token expires or the app is deleted and reinstalled of course.

I’ve tested so many games apps everywhere it works, why not for me ?

Please help me, otherwise I’ll go crazy…

P.S. My Facebook Developer Account have Live Status, I tested all in real with Live Status.

I notice you did not mention even once looking in the device logs. This should always be the first stop. See paragraph below on debugging on device, or just use adb logcat to find out what’s happening.

You must find a way to get the information you need in order to reason about what the problem is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

What is often happening in these cases is one of the following:

  • the code you think is executing is not actually executing at all
  • the code is executing far EARLIER or LATER than you think
  • the code is executing far LESS OFTEN than you think
  • the code is executing far MORE OFTEN than you think
  • the code is executing on another GameObject than you think it is
  • you’re getting an error or warning and you haven’t noticed it in the console window

To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run? what order does it run in?
  • what are the values of the variables involved? Are they initialized? Are the values reasonable?
  • are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

Knowing this information will help you reason about the behavior you are seeing.

You can also supply a second argument to Debug.Log() and when you click the message, it will highlight the object in scene, such as Debug.Log("Problem!",this);

If your problem would benefit from in-scene or in-game visualization, Debug.DrawRay() or Debug.DrawLine() can help you visualize things like rays (used in raycasting) or distances.

You can also call Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene manually, looking for all the parts, where they are, what scripts are on them, etc.

You can also call GameObject.CreatePrimitive() to emplace debug-marker-ish objects in the scene at runtime.

You could also just display various important quantities in UI Text elements to watch them change as you play the game.

**If you are running a mobile device you can also view the console output. Google for how on your particular mobile target, such as this answer or iOS: How To - Capturing Device Logs on iOS or this answer for Android: How To - Capturing Device Logs on Android **

Another useful approach is to temporarily strip out everything besides what is necessary to prove your issue. This can simplify and isolate compounding effects of other items in your scene or prefab.

Here’s an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

When in doubt, print it out!™

Note: the print() function is an alias for Debug.Log() provided by the MonoBehaviour class.