Search code examples
androidfacebookandroid-facebookandroid-sharing

Unable to share on Facebook


I have integrated Facebook SDK into my project. I have followed all the steps mentioned in https://developers.facebook.com/docs/android/getting-started/facebook-sdk-for-android/ .

But then also I am not able to share on facebook. I have generated the hash using debug.keystore and have placed it at 2 places as mentioned in the documentation.

Issue: I am able to share on facebook if native facebook android app is not installed in the device. i.e. via the pop up which ask for email id and password. I don't know why it doesn't share if facebook app is installed.

Edit: Even I downloaded the latest samples and sdk of Facebook which https://developers.facebook.com/android/ provides. There also I faced this same issue. Even I tried in many device.


Solution

  • I am able to Proceed with this now. The issue was with key hash which I was including in facebook developers site. I was getting wrong key due to openssl. I got the correct one by including this piece of code:

    try {
        PackageInfo info = getPackageManager().getPackageInfo(
              YOUR_PACKAGE_NAME, PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) 
            {
               MessageDigest md = MessageDigest.getInstance("SHA");
               md.update(signature.toByteArray());
               Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
        }
    } catch (NameNotFoundException e) {
    } catch (NoSuchAlgorithmException e) {
    }
    

    I got this while I was searching for alternative to generate the key hash.