B4A Library Facebook - Extends FirebaseAuth to support Facebook

Discussion in 'Additional libraries, classes and official updates' started by Erel, Jun 15, 2016.

  1. Erel

    Erel Administrator Staff Member Licensed User

    This library requires B4A v6+.


    This library together with FirebaseAuth allows users to sign in to your app with a Facebook or Google account.

    Start with configuring FirebaseAuth: https://www.b4x.com/android/forum/threads/firebaseauth-authenticate-your-users.67875/
    Once it works you can follow these instructions to add support for Facebook.

    Download Facebook SDK v4.14.0: https://origincache.facebook.com/developers/resources/?id=facebook-android-sdk-4.14.0.zip

    Find a file named facebook-android-sdk-xx.xx.xx.aar in the SDK.

    You need to rename it to: facebook-android-sdk.aar and copy it to the additional libraries folder.

    You should create a facebook app with an Android platform:

    Enable Facebook in Firebase console: Auth - Sign In Method:

    Add the OAuth redirect URI from Firebase to Facebook Login product:

    You will need to follow these instructions to create a hash key from B4A signing key: https://developers.facebook.com/docs/android/getting-started#release-key-hash
    The alias in the command should be B4A.

    Add the following snippet to the manifest editor:
    '************ Facebook Login ****************
    AddApplicationText( <activity
    "@android:style/Theme.Translucent.NoTitleBar" />
              <meta-data android:name=
    "com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>)

    '************ Facebook Login (end) **********
    CreateResource(values, facebook.xml, <resources>
    string name="facebook_app_id">123123123123</string>
    Replace the number with your Facebook app id.

    The code itself is simple. You need to initialize FacebookSdk in the starter service.
    Call SignIn from an Activity to sign in.
    Note that the user will sign in automatically after the first time.

    Auth_SignedIn event is raised after the user signs in.

    Firebase instructions: https://firebase.google.com/docs/auth/android/facebook-login
    Facebook instructions: https://developers.facebook.com/docs/facebook-login/android

    Note that you need to "make the app public" before other users can log in:



    v1.01 - Based on Facebook SDK 5.50. It depends on AppCompat which should be added in the libraries tab.

    Download link: www.b4x.com/android/files/facebook-5.5.0.zip

    Attached Files:

    Last edited: Sep 8, 2019
  2. tufanv

    tufanv Expert Licensed User

    Can we get their facebook info also with this or just the sign in ?
  3. Erel

    Erel Administrator Staff Member Licensed User

    You are getting a FirebaseUser with the name, email and the Firebase Uid. Currently this is the only information exposed.
    valentino s and b4auser1 like this.
  4. Brian Robinson

    Brian Robinson Active Member Licensed User

    That's Awesome... Is Twitter next? ;)
    damianccs likes this.
  5. bluedude

    bluedude Well-Known Member Licensed User

    Are we going to have one Firebase library covering all in the end?
  6. DonManfred

    DonManfred Expert Licensed User

    NOT with this lib. It is only for authenticating a user. It will not allow to share something or post on the wall...
    lemonisdead likes this.
  7. Erel

    Erel Administrator Staff Member Licensed User

    No. Putting everything in the same library will make it more difficult for developers to use as the features depend on other Sdks (for example Facebook Sdk).
    Multiverse app and lemonisdead like this.
  8. sanjibnanda

    sanjibnanda Active Member Licensed User

    is facebook-android-sdk.aar is deliberate extension or a mistake as compiler issue error with both .rar and .aar

    with .rar

    Could not find file 'C:\Program Files (x86)\Anywhere Software\Basic4android\libraries\facebook-android-sdk.aar'.

    and with .aar

    Generating R file. Error
    Cannot find central directory

    however i have completed all steps and stuck here. thanks for the updates.

    the most difficult part was to get the hash key. and for me this method worked, may be helpful to some one.

    http://stackoverflow.com/questions/5306009/facebook-android-generate-key-hash (use alias b4a)
    Last edited: Jun 19, 2016
    Marcus Araujo likes this.
  9. sanjibnanda

    sanjibnanda Active Member Licensed User

    fixed, it works now i had put wrong files. sorry for botheration.
  10. shashkiranr

    shashkiranr Active Member Licensed User

    Hi All,

    First time when I signin with facebook everything works and I get the user email id. But from next time onwards I am just getting these messages in the logs and nothing happens.

    sending message to waiting queue (OnActivityResult)
    running waiting messages (
    And if I check Starter.FireBaseAuth.CurrentUser.IsInitialized then its not initialized.

    kindly let me know what might I be doing wrong.

  11. Erel

    Erel Administrator Staff Member Licensed User

    Have you tried to sign out before signing in again?
  12. tuhatinhvn

    tuhatinhvn Active Member Licensed User

    Can i get list friends of user facebook???
  13. DonManfred

    DonManfred Expert Licensed User

    Not with this library. It only returns the email and maybe name.

    You are searching for a wrapper for the Facebook SDK whih does not exist as yet (as i know of).
    shashkiranr likes this.
  14. shashkiranr

    shashkiranr Active Member Licensed User

    Erel I tried signing out and logging in and its not working. I removed the app from my Facebook account and again tried to log in but the same. Also I created a new Facebook app and tried, still getting the same.

  15. Erel

    Erel Administrator Staff Member Licensed User

    1. Do you see the user in Firebase console?


    2. If you uninstall the app and then install it are you able to sign in once?

    3. Are you using the Facebook app to sign in or does it open an internal WebView?

    Check the unfiltered logs. There might be more information.
  16. chuath

    chuath Member Licensed User

    I have implemented both Google and Facebook Auth successfully.
    However i encounter a strange bug when both Google and Facebook are using the SAME email.

    When i login to Facebook first then logout, then i try to login using Google. I would be getting the Facebook ID in the FirebaseUser.
    This is fine. No problem. I can live with that.

    However, IF i do the opposite something strange would happen.
    I proceed with a clean state by deleting the user from Firebase console first then start the reverse process.
    Google first then logout and login with Facebook. I would not be getting any ID at all.
    "Auth_SignedIn" doesn't fire and i have no way to capture this error.

    Is there any way to capture this so that i could inform the user to use back the Google Auth or automate it for them?

    I've tried the option to enable "Multiple account per email address" under Firebase but the result would be an empty field for Email for the duplicated entry.
    I needed the email entry to verify with my own user database. Therefore this method is not viable for me.
  17. Erel

    Erel Administrator Staff Member Licensed User

    Have you checked the unfiltered logs? Are there any error messages?
  18. chuath

    chuath Member Licensed User

    Nothing shown for unfiltered log except this
    sending message to waiting queue (OnActivityResult)
    running waiting messages (
    This is shown when using google signin too when everything is normal.
    I think we lack an event listener for ActivityResult?
  19. Erel

    Erel Administrator Staff Member Licensed User

    Are you connected with B4A-Bridge or USB debug mode? Try with USB debug mode, it will allow you to see all the logs.

    It probably failed to sign in to Google.
  20. shashkiranr

    shashkiranr Active Member Licensed User

    Hi Erel,

    The below error message is from the unfiltered logs when trying to signin with facebook

    Class not found when unmarshalling: com.facebook.login.LoginClient$Request
    java.lang.ClassNotFoundException: com.facebook.login.LoginClient$Request
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:
        at java.lang.Class.forName(Class.java:
        at android.os.Parcel.readParcelableCreator(Parcel.java:
        at android.os.Parcel.readParcelable(Parcel.java:
        at android.os.Parcel.readValue(Parcel.java:
        at android.os.Parcel.readArrayMapInternal(Parcel.java:
        at android.os.BaseBundle.unparcel(BaseBundle.java:
        at android.os.BaseBundle.getString(BaseBundle.java:
        at android.content.Intent.getStringExtra(
        at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:
        at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:
        at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:
        at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:
        at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:
        at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:
        at android.os.Binder.execTransact(Binder.java:
    Caused by: java.lang.ClassNotFoundException: Didn
    't find class "com.facebook.login.LoginClient$Request" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:
        at java.lang.ClassLoader.loadClass(ClassLoader.java:
    17 more
        Suppressed: java.lang.ClassNotFoundException: com.facebook.login.LoginClient$Request
            at java.lang.Class.classForName(Native Method)
            at java.lang.BootClassLoader.findClass(ClassLoader.java:
            at java.lang.BootClassLoader.loadClass(ClassLoader.java:
            at java.lang.ClassLoader.loadClass(ClassLoader.java:
    18 more
        Caused by: java.lang.NoClassDefFoundError: Class 
    not found using the boot class loader; no stack available
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice