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: 242
Last edited:

Alpandino

Member
Licensed User
You should never limit your questions to a single member.

I don't see how the timer is related to the authentication. My guess is that the problem is somewhere else.

I know it sound strange, but I did a lot of test and when I use a Timer object the the Auth_SignedIn event is not raised.
I'll do further experiments and I'll let you know.

Thanks
 

Daniel Uribe

Member
Licensed User
Longtime User
Hi Erel,

grettings from Venezuela

Nice to meet you, it´s great!!

I have a questions,

When i login first time no problem, after that i logout click and all ok.

The second time I click again log in with facebook and an error, it´s from facebook screen: (file.facebook_screen.png)

I don´t know why.. So, in the firebase console first I delete the registered user (look firebase_console.png)and after that from my facebook settings (not the facebook developer console but the normal user, look facebook_user_settings.png) and delete my app.

just so I could login it again.

This it´s the best way?
or is there another way

It´s a pleasure.

p.d: it´s posible get the profile image of user when log in with facebook or gmail?
 

Attachments

  • facebook_screen.png
    facebook_screen.png
    24 KB · Views: 282
  • facebook_user_settings.png
    facebook_user_settings.png
    289 KB · Views: 275
  • firebase_console.png
    firebase_console.png
    120.7 KB · Views: 271
Last edited:

Alpandino

Member
Licensed User
I did other tests and... Ever was right, as usual.
The Timer doesn't influence the behavior of the authentication. It was my mistake: I initialized the FirebaseUser two time, one in the Starter Service, one in the main module. I removed this double initialization and now all works fine.
 

Daniel Uribe

Member
Licensed User
Longtime User
Are you signing out from both FacebookSDK and FirebaseAuth?

Yeap, when click signout button:


Sub btnSignOut_Click
Log("you click out!!")
Starter.auth.SignOutFromGoogle
Starter.facebook.SignOut
lblName.Text = "Goodbye!"
SetState
End Sub

setstate is same of your original code.

..Still error (facebook_screen.png) but in google work perfectly!!
 

Daniel Uribe

Member
Licensed User
Longtime User
Solved.

Was my key hash.. I put on facebook developer console with a bad number and facebook could not work properly.

I use another way to get the key hash

B4X:
Dim bc As ByteConverter
Dim raw() As Byte = bc.HexToBytes("85:58:1D:1D:E3:...".Replace(":", ""))
Dim su As StringUtils
Log(su.EncodeBase64(raw))

I get this code from you:

https://www.b4x.com/android/forum/threads/development-and-release-key-hash.59762/

Thanks a lot.!
 

StefanoAccorsi

Member
Licensed User
Longtime User
Thanks a lot @Erel. Configured and it works like a charm.

Now I'll wait for a method to get the AccessToken. Next, if I undestood it well, with an AccessToken you should be able to work with Graphs API with simple HTTP get and post and ... get or post whatever you want in FB.
 

devpialkt

Member
Licensed User
Longtime User
Need Help ,

When add Facebook.jar and Facebook.xml into B4A then compile it , I have this Error ...

upload_2016-10-18_14-0-39.png
 

Attachments

  • upload_2016-10-18_13-57-56.png
    upload_2016-10-18_13-57-56.png
    25 KB · Views: 203

ercicco

New Member
Licensed User
I have this problem with Firebase when try to compile the code, some solution???
I have installed all reposition...

FirebaseAuth\Objects\bin\extra\res1\res\values\values.xml:122: error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.NoActionBar'.
 

tamba sylvester

Member
Licensed User
Longtime User
hello guys
when i try to build the above projects it gives me this error

Generating R file. Error
F:\FirebaseAuth\Objects\bin\extra\res1\res\values\values.xml:122: error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.NoActionBar'.
F:\FirebaseAuth\Objects\bin\extra\res1\res\values\values.xml:127: error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.Dialog'.
 

DonManfred

Expert
Licensed User
Longtime User
when i try to build the above projects it gives me this error
This is not related to this library. You should start a new thread in the questions forum and upload your project. I´m sure you have an error in your app´s setup for AppCompat....
 

tamba sylvester

Member
Licensed User
Longtime User
i get this error when i compile the application above

B4A version: 6.30
Parsing code. (0.01s)
Compiling code. (0.04s)

ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
Generating R file. Error
F:\FirebaseAuth\Objects\bin\extra\res1\res\values\values.xml:122: error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.NoActionBar'.
F:\FirebaseAuth\Objects\bin\extra\res1\res\values\values.xml:127: error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.Dialog'.
 

tamba sylvester

Member
Licensed User
Longtime User
This is not related to this library. You should start a new thread in the questions forum and upload your project. I´m sure you have an error in your app´s setup for AppCompat....
it relates coz i cant run the firebase facebook auth in my IDE IT BRINGS that error shown
 
Top