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

shashkiranr

Active Member
Licensed User
Longtime User
Hi Erel,

I have copied the .aar file as mentioned in the libraries folder. I am using galaxy s6 active.

Best,
SK
 

jazzzzzzz

Active Member
Licensed User
Longtime User
I have successfully setup facebook login here,but I can login using my developer enabled facebook account only in my App.(no success callback came to app for other logins)

I have enabled 'make my app public' in app review setting in facebook

I have tested both in webview login and in a phone with facebook installed and this is the case in both options
check the attachment for setting



B4X:
Local module descriptor class for com.google.firebase.auth not found.
on a succesfull login and an unsuccesfull login I see the message above in unfiltered log ,Is that normal??

please see the screenshot below...Somebody tried with other facebook account?
 

Attachments

  • screen.png
    screen.png
    44.2 KB · Views: 302
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
on a succesfull login and an unsuccesfull login I see the message above in unfiltered log ,Is that normal??
Do you see it in the filtered logs?

Can you post the logs?


Somebody tried with other facebook account?
Yes, it works here fine with other Facebook accounts.
 

jazzzzzzz

Active Member
Licensed User
Longtime User
Dropping non-bitmap icon from notification.
uevent_handler [349] LOCK 0xb6c5606c from 531
uevent_handler mutex 0xb6c5606c GOT by 531
uevent_handler [383] UNLOCK 0xb6c5606c from 531
Old PowerLevel: 6, current PowerLevel: 6
onReceive() : Charging = true
Timeline: Activity_launch_request id:com.snapnwin time:35434695
START u0 {act=NATIVE_WITH_FALLBACK cmp=com.snapnwin/com.facebook.FacebookActivity (has extras)} from uid 10316 on display 0
** Activity (main) Pause, UserClosed = false **
[InputMethodManagerWrapper.java:30] Constructor
onDetachedFromWindow called when already detached. Ignoring
[InputMethodManagerWrapper.java:59] isActive: false
ImeThread is not enabled.
Dropping non-bitmap icon from notification.
Displayed com.snapnwin/com.facebook.FacebookActivity: +119ms
Timeline: Activity_idle id: android.os.BinderProxy@b8133c4 time:35434850
Timeline: Activity_windows_visible id: ActivityRecord{6021796 u0 com.snapnwin/com.facebook.FacebookActivity t212} time:35435099
Cannot call determinedVisibility() - never saw a connection for the pid: 12279
[InputMethodManagerWrapper.java:59] isActive: false
Dropping non-bitmap icon from notification.
Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@aaad82b attribute=android.view.inputmethod.EditorInfo@4dd5488, token = android.os.BinderProxy@40efced
Dropping non-bitmap icon from notification.
uevent_handler [349] LOCK 0xb6c5606c from 531
uevent_handler mutex 0xb6c5606c GOT by 531
uevent_handler [383] UNLOCK 0xb6c5606c from 531
onReceive() : Charging = true
Old PowerLevel: 6, current PowerLevel: 6
Old PowerLevel: 6, current PowerLevel: 6
onReceive() : Charging = true
[INFO:CONSOLE(0)] "Deferred long-running timer task(s) to improve scrolling smoothness. See crbug.com/574343.", source: https://m.facebook.com/v2.6/dialog/oauth/confirm (0)
[INFO:CONSOLE(0)] "Deferred long-running timer task(s) to improve scrolling smoothness. See crbug.com/574343.", source: https://m.facebook.com/v2.6/dialog/oauth/confirm (0)
[INFO:CONSOLE(0)] "Deferred long-running timer task(s) to improve scrolling smoothness. See crbug.com/574343.", source: https://m.facebook.com/v2.6/dialog/oauth/confirm (0)
[INFO:CONSOLE(0)] "Deferred long-running timer task(s) to improve scrolling smoothness. See crbug.com/574343.", source: https://m.facebook.com/v2.6/dialog/..._type=token,signed_request&return_scopes=true (0)
[InputMethodManagerWrapper.java:59] isActive: true
[InputMethodManagerWrapper.java:68] hideSoftInputFromWindow
Dropping non-bitmap icon from notification.
Cannot call determinedVisibility() - never saw a connection for the pid: 12279
[InputMethodManagerWrapper.java:59] isActive: true
[InputMethodManagerWrapper.java:68] hideSoftInputFromWindow
uevent_handler [349] LOCK 0xb6c5606c from 531
uevent_handler mutex 0xb6c5606c GOT by 531
uevent_handler [383] UNLOCK 0xb6c5606c from 531
Old PowerLevel: 6, current PowerLevel: 6
onReceive() : Charging = true
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
** Activity (main) Resume **
Bound to Google auth api service! :)
Old PowerLevel: 6, current PowerLevel: 6
onReceive() : Charging = true
Timeline: Activity_idle id: android.os.BinderProxy@9869234 time:35438226
client connected with version: 9256000
Starting operation: >> dmt
Finished operation: << dmt (10ms elapsed)
Sending connection
Starting operation: >> dms
Executing request: ProxyRequest[ url: https://www.googleapis.com/identity...n?key=AIzaSyDPj3O2C1Ql9JgIzsti2FhSQofzPzQIoXY, method: 1 ]
Dropping non-bitmap icon from notification.
Executing send connection operation
Finished operation: << dms (670ms elapsed)
starting scan for "Senzit_India"-WPA_PSK with 2412
Dropping non-bitmap icon from notification.
Dropping non-bitmap icon from notification.
Dropping non-bitmap icon from notification.
uevent_handler [349] LOCK 0xb6c5606c from 531
uevent_handler mutex 0xb6c5606c GOT by 531
uevent_handler [383] UNLOCK 0xb6c5606c from 531
Old PowerLevel: 6, current PowerLevel: 6
onReceive() : Charging = true
Old PowerLevel: 6, current PowerLevel: 6
onReceive() : Charging = true
Dropping non-bitmap icon from notification.
vendor/qcom/proprietary/RIDL/RIDLClient/RIDLSQL.cpp:2500: GetTransState() EBADF
vendor/qcom/proprietary/RIDL/RIDLClient/MainCore.cpp:1550: Failed to get TransState, rc 9
vendor/qcom/proprietary/RIDL/RIDLClient/RIDLSQL.cpp:2500: GetTransState() EBADF
vendor/qcom/proprietary/RIDL/RIDLClient/RIDLSQL.cpp:2500: GetTransState() EBADF
uevent_handler [349] LOCK 0xb6c5606c from 531
uevent_handler mutex 0xb6c5606c GOT by 531
uevent_handler [383] UNLOCK 0xb6c5606c from 531
Old PowerLevel: 6, current PowerLevel: 6
onReceive() : Charging = true
Old PowerLevel: 6, current PowerLevel: 6
onReceive() : Charging = true
Dropping non-bitmap icon from notification.
uevent_handler [349] LOCK 0xb6c5606c from 531
uevent_handler mutex 0xb6c5606c GOT by 531
uevent_handler [383] UNLOCK 0xb6c5606c from 531
Old PowerLevel: 6, current PowerLevel: 6
onReceive() : Charging = true
Old PowerLevel: 6, current PowerLevel: 6
onReceive() : Charging = true
Dropping non-bitmap icon from notification.

please check this log
 

jazzzzzzz

Active Member
Licensed User
Longtime User
I dont know why but sometimes i get only the attched page when trying to login.(I had logout properly earlier)

When i press ok nothing happens
 

jazzzzzzz

Active Member
Licensed User
Longtime User
After pressing the login button that page in the screen shot will come,I dont even know who is the user
 

jazzzzzzz

Active Member
Licensed User
Longtime User
B4X:
Dropping non-bitmap icon from notification.
Cannot call determinedVisibility() - never saw a connection for the pid: 23896
[InputMethodManagerWrapper.java:59] isActive: true
[InputMethodManagerWrapper.java:68] hideSoftInputFromWindow
[InputMethodManagerWrapper.java:42] restartInput
onFinishInput()
[InputMethodManagerWrapper.java:59] isActive: true
[InputMethodManagerWrapper.java:68] hideSoftInputFromWindow
Dropping non-bitmap icon from notification.
Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@fad1335 attribute=null, token = android.os.BinderProxy@ffdaa86
Dropping non-bitmap icon from notification.
vendor/qcom/proprietary/RIDL/RIDLClient/RIDLSQL.cpp:2500: GetTransState() EBADF
vendor/qcom/proprietary/RIDL/RIDLClient/MainCore.cpp:1550: Failed to get TransState, rc 9
vendor/qcom/proprietary/RIDL/RIDLClient/RIDLSQL.cpp:2500: GetTransState() EBADF
vendor/qcom/proprietary/RIDL/RIDLClient/RIDLSQL.cpp:2500: GetTransState() EBADF
Dropping non-bitmap icon from notification.
[INFO:CONSOLE(0)] "Deferred long-running timer task(s) to improve scrolling smoothness. See crbug.com/574343.", source: https://m.facebook.com/v2.6/dialog/oauth?redirect_uri=fbconnect%3A%2F%2Fsuccess&display=touch&state=%7B%220_auth_logger_id%22%3A%22b78a878b-723e-47c6-9e0f-63857861a122%22%2C%223_method%22%3A%22web_view%22%7D&scope=public_profile%2Cemail&response_type=token%2Csigned_request&default_audience=friends&return_scopes=true&auth_type=rerequest&client_id=1649629785364125&ret=login&sdk=android-4.13.2&logger_id=b78a878b-723e-47c6-9e0f-63857861a122&refsrc=https%3A%2F%2Fm.facebook.com%2Flogin.php&locale2=ml_IN&_rdr#_=_ (0)
[InputMethodManagerWrapper.java:59] isActive: true
[InputMethodManagerWrapper.java:68] hideSoftInputFromWindow
Dropping non-bitmap icon from notification.
NeighborEvent{elapsedMs=108079051, 192.168.0.1, [78542E5D1360], RTM_NEWNEIGH, NUD_REACHABLE}
Cannot call determinedVisibility() - never saw a connection for the pid: 23896
[InputMethodManagerWrapper.java:59] isActive: true
[InputMethodManagerWrapper.java:68] hideSoftInputFromWindow
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
** Activity (main) Resume **
Local module descriptor class for com.google.firebase.auth not found.
Local module descriptor class for com.google.firebase.auth not found.
Timeline: Activity_idle id: android.os.BinderProxy@98cd50e time:38037647
Bound to Google auth api service! :)
client connected with version: 9256000
Starting operation: >> dmt
Finished operation: << dmt (9ms elapsed)
Sending connection
Starting operation: >> dms
Executing request: ProxyRequest[ url: https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyAssertion?key=AIzaSyDPj3O2C1Ql9JgIzsti2FhSQofzPzQIoXY, method: 1 ]
[WARNING:spdy_session.cc(2593)] Received WINDOW_UPDATE for invalid stream 49
Dropping non-bitmap icon from notification.
Executing send connection operation
Finished operation: << dms (695ms elapsed)
uevent_handler [349] LOCK 0xb6c5606c from 531
uevent_handler mutex 0xb6c5606c GOT by 531
uevent_handler [383] UNLOCK 0xb6c5606c from 531

I think after activity resume i got this error Local module descriptor class for com.google.firebase.auth not found.

any ideas?
login is working only for the first time for a single user i dont know whats happening.

I have tested it with your sample app but not logging in that too...
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
After pressing the login button that page in the screen shot will come,I dont even know who is the user
This is how Facebook login works. It cannot be changed.

login is working only for the first time for a single user i dont know whats happening.
Does it only happens with Facebook logins?
 

jazzzzzzz

Active Member
Licensed User
Longtime User
yes,google login is perfect..

can you try signing out from sample app and login again repeatedly for 3 users? I think that makes the error for facebook
 

DoctorDebug

Member
Licensed User
Longtime User
Hi, I set up an app to use Facebook as in the instructions, but when I compile I get:

\Objects\bin\extra\res1\res\values-v23\values-v23.xml:4: error: Error: No resource found that matches the given name (at 'cardBackgroundColor' with value '?android:attr/colorBackgroundFloating').

This has me dead in the water, has anyone else seen this, and, if so... help?

Thanks

Jeff
 

DoctorDebug

Member
Licensed User
Longtime User
Thanks, Erel, that got me around that issue... but this recent SDK upgrade is giving me fits. I will open a new thread about it though cause its not related to facebook.
 

pedrocam

Member
Licensed User
Longtime User
Hey guys,

Just wanted to share how i finally generated the hash key that facebook requires. I'm on windows and it took me a while so I hope to help you do it quicker.

Facebook says that to generate your key hashes you should use the following:
keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl base64

But for me I had to adjust some settings and below is what worked for me on the command prompt with adm privileges:

"C:\Program Files\Java\jdk1.8.0_73\bin\keytool.exe" -exportcert -alias B4A -keystore C:\Users\%MYPATH%\programming\B4A\New%20Firebase\firebase1.keystore | "C:\cygwin64\bin\openssl.exe" sha1 -binary | "C:\cygwin64\bin\openssl.exe" base64

Hope this helps!

PS. I had to have cygwin64 installed because that brought the openssl.exe file with it. Its free. but maybe if you find a different source for the openssl.exe file you can use that, and modify the filepath.
 
Last edited:

Alpandino

Member
Licensed User
Auth_SignedIn event is raised after the user signs in.

Hi Elver,
I noted a strange thing: in my app I have a timer in the Main. With this Timer (also if disabled), the Auth_SignedIn event is NOT raised.
If I remove the timer from the code Auth_SignedIn works.
I need this timer, how can I solve this problem?

Thank you
 

Alpandino

Member
Licensed User
Hi Elver,
I noted a strange thing: in my app I have a timer in the Main. With this Timer (also if disabled), the Auth_SignedIn event is NOT raised.
If I remove the timer from the code Auth_SignedIn works.
I need this timer, how can I solve this problem?

Thank you

Hi,
is there nobody that can help me to understand which is the problem?

Many thanks
 
Top