I'm trying to implement Facebook login into my app, and I'm facing a very peculiar issue, where the login process begins, fails with a very cryptic message and no exception is thrown on my app's side so I don't know what's going on.
I'm suspecting there is something to do with me using a DialogFragment
for my login process, and the Facebook LoginButton
is part of this DialogFragment
instead of a normal fragment or activity. I add the login button in my XML:
<com.facebook.login.widget.LoginButton
android:id="@+id/loginFacebookButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/default_margin_double"
android:layout_marginEnd="@dimen/default_margin_double"
android:layout_marginBottom="@dimen/default_margin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:background="@drawable/rounded_blue_bg"
android:layout_marginTop="@dimen/default_margin"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="@dimen/default_margin_double"
app:layout_constraintBottom_toTopOf="@id/loginOrLayout" />
And I add the callbacks in code, in my onCreateDialog
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState)
setStyle(STYLE_NORMAL, R.style.FullscreenDialog)
val view = View.inflate(context, R.layout.fragment_login, null)
//FB Login callback manager
val callbackManager = CallbackManager.Factory.create()
val fbLoginButton = view.loginFacebookButton
fbLoginButton.fragment = this
fbLoginButton.setPermissions(listOf("name", "email", "public_profile"))
fbLoginButton.loginBehavior = LoginBehavior.NATIVE_WITH_FALLBACK
fbLoginButton.registerCallback(callbackManager,
object : FacebookCallback<LoginResult> {
override fun onSuccess(loginResult: LoginResult) {
fbLoginSuccessful(loginResult)
}
override fun onCancel() {}
override fun onError(exception: FacebookException) {
Log.w(TAG, "onError: Failed to login with FB.", exception)
loginFailed(exception.localizedMessage)
}
})
return dialog
}
When I press the login button, I get a loading ProgressBar, then the Facebook app opens, I tap on my account, and then after some more loading, I get this screen:
I've followed the documentation here but I cannot seem to get it to work. Any help is greatly appreciated. I even printed the key hash from within my code as mentioned here in the documnetation, and I have the correct hashes ion the developer console, but still get the errors. Thank you
Facebook Login Error ‘Sorry, Something Went Wrong’. The “Sorry, Something Went Wrong. We are working on getting this fixed as soon as we can” Error while trying to log in or while opening a page can be due to the corruption of important data. This Error might also indicate a faulty extension that is preventing the page from being loaded.
Login Data: In some cases, the data login and other data being stored by the Facebook app might be the reason due to which this error is being triggered. The data might either be incorrect or corrupted which is why it might be preventing the login.
Besides, you can try to disable add-ons and extensions in the browser. The “something went wrong Facebook” issue may be caused by cookie and cache errors, incorrect login data, incorrect extensions, Facebook server issues, and Facebook permissions. Luckily, no matter which browser you use, you can find a solution here.
The Facebook Login SDK for Android is a component of the Facebook SDK for Android. To use the Facebook Login SDK in your project, make it a dependency in Maven, or download it.
It seems like I was missing the following in my fragment:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
callbackManager.onActivityResult(requestCode, resultCode, data)
super.onActivityResult(requestCode, resultCode, data)
}
However, It might have not been related, since the error was being thrown before the actual FB activity returned, so maybe it was an internal facebook error that has been fixed.
Good luck to anyone facing similar issues, the support for the FB SDK is virtually non existent.
Edit to add Sourabh comment: "I found the issue with my code. Turns out I was send permission "email" in capital letters (EMAIL). Had to check each and every line of my code multiple times. It sucks that they don't send a precise error message. –"
Following the comment of Sourabh, I fixed this error checking the permissions in the logIn facebook function. Double check your permissions and if it doesn't work, try to send just the email, to see if it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With