B4A Library Facebook - Extends FirebaseAuth to support Facebook

This library requires B4A v12.0+

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 and make sure to update facebook_app_id and the client token (https://developers.facebook.com/docs/facebook-login/guides/access-tokens#clienttokens):
B4X:
'************ Facebook Login ****************
CreateResource(values, facebook.xml, <resources>
    <string name="facebook_app_id">111111111111111</string>
   </resources>)
  
 AddApplicationText(<meta-data android:name="com.facebook.sdk.ClientToken" android:value="aaaaaaaaaabbbbbbbe053434346"/>)

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"/>)
  
AddApplicationText(
    <provider
            android:name="com.facebook.internal.FacebookInitProvider"
            android:authorities="${applicationId}.FacebookInitProvider"
            android:exported="false" />

        <receiver
            android:name="com.facebook.CurrentAccessTokenExpirationBroadcastReceiver"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.facebook.sdk.ACTION_CURRENT_ACCESS_TOKEN_CHANGED" />
            </intent-filter>
        </receiver>
        <receiver
            android:name="com.facebook.AuthenticationTokenManager$CurrentAuthenticationTokenChangedBroadcastReceiver"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.facebook.sdk.ACTION_CURRENT_AUTHENTICATION_TOKEN_CHANGED" />
            </intent-filter>
        </receiver>
       
         <activity
            android:name="com.facebook.FacebookActivity"
            android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:theme="@style/com_facebook_activity_theme" />
        <activity android:name="com.facebook.CustomTabMainActivity" />
        <activity
            android:name="com.facebook.CustomTabActivity"
            android:exported="true"
             >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="cct.${applicationId}"
                    android:scheme="fbconnect" />
            </intent-filter>
        </activity>
)

'************ Facebook Login (end) **********
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

v2.01 - Adds missing dependencies.
v2.00 - Based on Facebook 14.1.1
v1.04 - Based on Facebook 11.2
v1.02 - Based on Facebook SDK 7.0.0.
v1.01 - Based on Facebook SDK 5.50.

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

Attachments

  • FacebookExample.zip
    55.4 KB · Views: 225
Last edited:

DonManfred

Expert
Licensed User
Longtime User

MarcoRome

Expert
Licensed User
Longtime User
hi
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.

I realy don't understand, how to create a hash key. Sign in with google is working finr, but i'm lost in instructions for creating hash key.Any suggestions ?

As already suggestion in #49
B4X:
Dim bc As ByteConverter
Dim raw() As Byte = bc.HexToBytes("85:58:1D:1D:E3:...".Replace(":", "")) '<----- HERE "85:58:1D:1D:E3" YOUR PASTE SHA1
Dim su As StringUtils
Log(su.EncodeBase64(raw))

This Log(su.EncodeBase64(raw)) will give you Hash key
 

stari

Active Member
Licensed User
Longtime User
As already suggestion in #49
B4X:
Dim bc As ByteConverter
Dim raw() As Byte = bc.HexToBytes("85:58:1D:1D:E3:...".Replace(":", "")) '<----- HERE "85:58:1D:1D:E3" YOUR PASTE SHA1
Dim su As StringUtils
Log(su.EncodeBase64(raw))

This Log(su.EncodeBase64(raw)) will give you Hash key
THKS, @MarcoRome .
 

stari

Active Member
Licensed User
Longtime User
error by compile :
B4A version: 6.30
Parsing code. (0.10s)
Compiling code. (0.29s)
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
Generating R file. Error
D:\DocumentsD\Android\ELF1\EE PlayStore\EE_Final_V1.5_02_11\Objects\bin\extra\res1\res\values\values.xml:131: error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.NoActionBar'.
D:\DocumentsD\Android\ELF1\EE PlayStore\EE_Final_V1.5_02_11\Objects\bin\extra\res1\res\values\values.xml:136: error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.Dialog'.

What i miss ?
 

MarcoRome

Expert
Licensed User
Longtime User
error by compile :
B4A version: 6.30
Parsing code. (0.10s)
Compiling code. (0.29s)
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
Generating R file. Error
D:\DocumentsD\Android\ELF1\EE PlayStore\EE_Final_V1.5_02_11\Objects\bin\extra\res1\res\values\values.xml:131: error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.NoActionBar'.
D:\DocumentsD\Android\ELF1\EE PlayStore\EE_Final_V1.5_02_11\Objects\bin\extra\res1\res\values\values.xml:136: error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.Dialog'.

What i miss ?

AppCompat Library ? Do you have
 

stari

Active Member
Licensed User
Longtime User
Add a reference to FirebaseAnalytics library and see whether it works.
Yes, abalytics is working fine. Also sign in with google. When i add Sign in with Facebook, then i get this error. And, strange, if i remove Facebook, also this error persist.
I make Sign in on bassis of your sample.
Will AppCombad help, as say @MarcoRome ?
 

stari

Active Member
Licensed User
Longtime User
Works good.
Is there any possibility to sign in with other account but i still stay loged in Facebook with my account ?
 

desof

Well-Known Member
Licensed User
Longtime User
Download the example that EREL attached and I configured all the parameters but it does not allow me to execute it.
What's going on ?


B4A version: 6.50
Parsing code. (0.00s)
Compiling code. (0.02s)
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
Generating R file. Error
C:\Users\DeSof\Downloads\FacebookExample\FirebaseAuth\Objects\bin\extra\res1\res\values\values.xml:131: error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.NoActionBar'.
C:\Users\DeSof\Downloads\FacebookExample\FirebaseAuth\Objects\bin\extra\res1\res\values\values.xml:136: error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.Dialog'.
 
Last edited:
Top