B4A Library Facebook - Extends FirebaseAuth to support Facebook

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.

You should create a facebook app with an Android platform:
SS-2016-06-15_17.06.51.png


Enable Facebook in Firebase console: Auth - Sign In Method:
SS-2016-06-15_17.04.08.png


Add the OAuth redirect URI from Firebase to Facebook Login product:
SS-2016-06-15_17.08.38.png


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:
B4X:
'************ 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:

SS-2016-07-05_08.57.05.png



Updates

v1.02 - Based on Facebook SDK 7.0.0.
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-7.0.0.zip
 

Attachments

  • FacebookExample.zip
    54.7 KB · Views: 113
Last edited:

Marcus Araujo

Member
Licensed User
Only these lines caught my attention, but I am not sure if the first one has to do with my process.

Class com.facebook.appevents.AppEvent failed lock verification and will run slower.
Object context is paused. Ignoring CallSubDelayed: JobDone
 

Lucas Eduardo

Active Member
Licensed User
How can i configure my firebase project if i have made two apps with login facebook? There are two app id and two app secret, what do I put in these fields?
 

Devv

Active Member
Licensed User
Hello
thank you fro the great lib
however one of my app users is getting the following error
May 6, 5:36 AM on app version 44
Huawei nova 3i (HWINE), 3840MB RAM, Android 9
Report 1 of 1
java.lang.NullPointerException:

at com.facebook.internal.FetchedAppGateKeepersManager$2.run (FetchedAppGateKeepersManager.java:154)

at android.os.Handler.handleCallback (Handler.java:907)

at android.os.Handler.dispatchMessage (Handler.java:105)

at android.os.Looper.loop (Looper.java:216)

at android.app.ActivityThread.main (ActivityThread.java:7625)

at java.lang.reflect.Method.invoke (Native Method)

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:524)

at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:987)


i think in the latest version of the sdk they fixed this problem
can you please update the lib to the latest SDK ?
 

kstainsb

Member
Licensed User
V1.02 released. It is based on Facebook SDK v7.0.0.

I updated this, and get an error (see attached). Looking in the facebook.xml file it says:
<version>1.01</version>
<dependsOn>facebook-core-5.5.0.aar</dependsOn>
<dependsOn>facebook-login-5.5.0.aar</dependsOn>
<dependsOn>facebook-common-5.5.0.aar</dependsOn>
<dependsOn>com.android.support:cardview-v7</dependsOn>
I wonder if these need updating to 7.0.0., v.1.02..?
 

Attachments

  • err.png
    err.png
    18.8 KB · Views: 74

Stevenindonesia

Member
Licensed User
Erel,

I have downloaded the Facebook Example.zip. Tried to compile application but with error below :

Compiling resources (0.87s)
Linking resources Error
error: resource style/Theme.AppCompat.NoActionBar (aka com.TWorld.PBrowser:style/Theme.AppCompat.NoActionBar) not found.
error: resource style/Theme.AppCompat.Dialog (aka com.TWorld.PBrowser:style/Theme.AppCompat.Dialog) not found.
error: failed linking references.

Checked on AppCompat library but still the same thing. What went wrong?
 

Erel

Administrator
Staff member
Licensed User
I've updated the example.

It compiled fine with the AppCompat library. I guess that your SDK is misconfigured. Delete your SDK. Upgrade to B4A v10.9 and download the updated resources.
 

Stevenindonesia

Member
Licensed User
Erel,

Thank for your fast response. I uninstalled all SDK and reinstall the latest from your installation tutorial. Everything works just fine now.

Thanks!!
 

Stevenindonesia

Member
Licensed User
Hi Erel,

I have been trying to generate 'Key Hashes' in Facebook Developer with command as such :
* FOR DEBUG
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

* FOR RELEASE
keytool -exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore /Users/***/Documents/keystore/***.jks | openssl sha1 -binary | openssl base64

The facebook demo app works - (But just google log in)
As for facebook, It is still not working. I suspect the 'Key Hashes' is the problem here.

Where can we get a clearer writeup to generate 'Key Hashes' for b4a? Other programming languages has terminals... but not b4a.

Sorry i am a little confuse with this.
 

Stevenindonesia

Member
Licensed User
Hi all,
I just recently got facebook login working. The funny thing is that the facebook does not return email address. Is there any particular thing that i need to set? or maybe in facebook developer? Anyone?

Thanks
 
Top