Android Question Firebase Facebook Authentication - B4i events uniformization

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Hello all,

Using Facebook library to authenticate in B4i I noticed that, when an authentication error occurred, the library was receiving the error event but wasn't triggering it in B4i which turned impossible to manage error conditions. @Erel updated B4i Facebook library in this post : https://www.b4x.com/android/forum/threads/firebase-facebook-authentication.130898/#post-828821 , which fixed the problem for IOS.
Now I have the same issue in B4A (the FB error event is showed in log but doesn't trigger an event). I think that's the same situation.
Is there any workaround here or the unique solution is to create an updated Facebook library in B4A (adding the event facebook.initialize2(event_name) like @Erel did in the equivalent thread in b4i?)

Does anybody can help?

Thanks community!
 

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Can you post the logs when there is an error?
Hello @Erel ,

Good morning ! Follows the log :
Facebook - SignIn
** Activity (mainpage) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
Facebook - ResultArrived: Intent { (has extras) }
Facebook success: com.facebook.login.LoginResult@7ce501c
signInWithCredential start
** Activity (mainpage) Resume **
signInWithCredential complete: false
error: com.google.firebase.auth.FirebaseAuthUserCollisionException: An account already exists with the same email address but different sign-in credentials. Sign in using a provider associated with this email address.

Note that I implemented login with Google or Login with FaceBook. If the same e-mail registered in Facebook is already registered in Firebase as google login, Firebase raises this error which doesn't trigger the respective event in B4A (the same was happening in B4i but you updated the library that).
In the opposite situation (an email registered in Firebase using Facebook), when trying to login in Google, Firebase simply overrides Facebook login replacing the system authentication method in it's users database to Google (probably because Firebase is a Google product :D).
That's it. Its the same situation described in B4i with Facebook library.

Thanks @Erel !
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Please try the attached update (1.03). I haven't tested it myself.

You need to use FacebookSdk.Initialize2 and it will raise the SignError event in the module where FacebookSdk was initialized.
Thanks @Erel . I'm testing now and will post the results here.
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Please try the attached update (1.03). I haven't tested it myself.

You need to use FacebookSdk.Initialize2 and it will raise the SignError event in the module where FacebookSdk was initialized.
Hello @Erel,

I just finished to test and worked perfectly. But I noticed some details those could be important before to release the upgrade:

1. You told that this lib release should be 1.03. But in B4A panel, even after replacing the lib, the version remains 1.02 (I tested two times, closed and reopened the framework). Probably you forgot to change the version code. See:
1623938380844.png


2. When the user cancels the authentication (if the password is incorrect or even if he gives up), Fb raises a "Result" which doesn't raises an event in B4A. This event is raised in B4i and is important because if the app showed a progress dialog when the user called the authentication process it's not possible to dismiss the dialog in the case of user cancel. Follows the log for your convenience:

Facebook - SignIn
** Activity (mainpage) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
Facebook - ResultArrived: Intent { (has extras) }
Facebook cancel
** Activity (mainpage) Resume **

Finally, I tested the successful login, which worked perfectly. Follows the log:
Facebook - SignIn
** Activity (mainpage) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
Facebook - ResultArrived: Intent { (has extras) }
Facebook success: com.facebook.login.LoginResult@6a9ab7a
signInWithCredential start
** Activity (mainpage) Resume **
onAuthStateChanged: com.google.firebase.auth.internal.zzn@ff3229f
signInWithCredential complete: true
** Activity (mainpage) Pause, UserClosed = true **
Killing previous instance (partnersearch).
** Activity (partnersearch) Create, isFirst = false **
** Activity (partnersearch) Resume **

That's it. In my situation the new library is perfect. To publish as a release I think that it's needed to fix the version code (1.02 -> 1.03) and maybe to add the cancel event.

Again, thanks @Erel for your agility and kindness as always. B4X is certainly the worlds best framework for multiplatform development because your efforts! Thanks!
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
1. You told that this lib release should be 1.03. But in B4A panel, even after replacing the lib, the version remains 1.02 (I tested two times, closed and reopened the framework). Probably you forgot to change the version code. See:
1623938380844.png
Forget this. My fault ! :D On line version 1.02. Local version 1.03. Correct!
 
Upvote 0
Top