Search code examples
androidfacebookkotlinfacebook-graph-apifacebook-android-sdk

Login with Facebook latest sdk if native app install then dialog not open in android


I am using latest Facebook-sdk for Login with Facebook

 implementation 'com.facebook.android:facebook-login:[5,6)'

Try to login with facebook using custom button I am also getting this error in Facebook-android-sdk github issue https://github.com/facebook/facebook-android-sdk/issues/580 this issue resolved or not.

I want to open dialog if Facebook native app install, for that first I logout using LoginManager.getInstance().logOut()

I use default login manager like LoginManager.getInstance(), then login and logout , but when i check token after logout like this AccessToken.getCurrentAccessToken() it still exists

Below are my code:

callbackManager =
    CallbackManager.Factory.create()

    LoginManager.getInstance().logOut()
loginManager = LoginManager.getInstance()

LoginManager.getInstance()
    .registerCallback(callbackManager, object : FacebookCallback<LoginResult> {
        override fun onSuccess(loginResult: LoginResult) {
            val graphRequest = GraphRequest.newMeRequest(loginResult.accessToken)
            { jsonObj, _ ->

            }
            val parameters = Bundle()
            parameters.putString("fields", "id,name,email")
            graphRequest.parameters = parameters
            graphRequest.executeAsync()
        }

        override fun onCancel() {
        }

        override fun onError(error: FacebookException) {
            var msg = ""

        }
    })
loginManager.logInWithReadPermissions(
    this@SignUpActivity,
    listOf("email", "public_profile")
)

Manifest file

<meta-data android:name="com.facebook.sdk.ApplicationId"
    android:value="@string/facebook_app_id"/>

<activity android:name="com.facebook.FacebookActivity"
    android:configChanges=
        "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:label="@string/app_name" />

Solution

  • Finally, I found solution after lots of research and read many answers.

    If your app in development mode then generate Development Key Hash

    For Windows use following command:

    • Download openSSl from openssl-for-windows openssl library and Extract it.
    • Create a folder- OpenSSL in C:/ and copy the extracted code there.
    • To generate a development key hash, run the following command in a command prompt in the Java SDK folder
    • Change USERNAME with your username
    • This command will generate a 28-character key hash unique to your development environment. Copy and paste it into the field of Facebook developer site

    keytool -exportcert -alias androiddebugkey -keystore "C:\Users\USERNAME\.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary | "C:\OpenSSL\bin\openssl" base64


    If your app in Release mode then Generate a Release Key Hash

    keytool -exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore YOUR_RELEASE_KEY_PATH | openssl sha1 -binary | openssl base64

    Hope this save your time...