Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Facebook login fails without an exception, just "Sorry something went wrong"

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:

Facebook Login Error

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

like image 476
Lucas P. Avatar asked Nov 19 '19 08:11

Lucas P.


People also ask

Why does Facebook say sorry something went wrong when logging in?

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.

Why can’t I login to my Facebook app?

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.

How to fix “something went wrong on Facebook” issue?

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.

What is the Facebook login SDK for Android?

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.


2 Answers

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.

like image 168
Lucas P. Avatar answered Sep 19 '22 15:09

Lucas P.


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.

like image 37
Fabián Bardecio Avatar answered Sep 19 '22 15:09

Fabián Bardecio