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+.

    upload_2016-6-15_16-47-39.png

    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: https://developers.facebook.com/docs/android/
    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:
    [​IMG]

    Enable Facebook in Firebase console: Auth - Sign In Method:
    [​IMG]

    Add the OAuth redirect URI from Firebase to Facebook Login product:
    [​IMG]

    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:
    Code:
    '************ Facebook Login ****************
    AddApplicationText(<activity android:name="com.facebook.FacebookActivity"
      android:configChanges=
      
    "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
      android:theme=
    "@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>
       </resources>)
    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:

    [​IMG]
     

    Attached Files:

    Last edited: Jul 5, 2016
  2. tufanv

    tufanv Well-Known Member 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).
     
    lemonisdead likes 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
  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.

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

    kindly let me know what might I be doing wrong.

    Best,
    SK
     
  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.

    Best,
    SK
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    1. Do you see the user in Firebase console?

    [​IMG]

    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
    Code:
    sending message to waiting queue (OnActivityResult)
    running waiting messages (
    1)
    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


    Code:
    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:
    309)
        at java.lang.Class.forName(Class.java:
    273)
        at android.os.Parcel.readParcelableCreator(Parcel.java:
    2281)
        at android.os.Parcel.readParcelable(Parcel.java:
    2245)
        at android.os.Parcel.readValue(Parcel.java:
    2152)
        at android.os.Parcel.readArrayMapInternal(Parcel.java:
    2485)
        at android.os.BaseBundle.unparcel(BaseBundle.java:
    221)
        at android.os.BaseBundle.getString(BaseBundle.java:
    918)
        at android.content.Intent.getStringExtra(
    Intent.java:5767)
        at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:
    2374)
        at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:
    1857)
        at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:
    6043)
        at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:
    5827)
        at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:
    143)
        at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:
    4020)
        at android.os.Binder.execTransact(Binder.java:
    461)
    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:
    511)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:
    469)
        ... 
    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:
    781)
            at java.lang.BootClassLoader.loadClass(ClassLoader.java:
    841)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:
    504)
            ... 
    18 more
        Caused by: java.lang.NoClassDefFoundError: Class 
    not found using the boot class loader; no stack available
    Best,
    SK
     
Loading...