简体   繁体   中英

ShareDialog isn't showed when sharing a link to facebook from android application

I had an android application call Health with FacebookApp sharing feature. It's working right with FacebookApp_A (when I click to share, it shows sharedialog).

I want replace FacebookApp_A by FacebookApp_B.

Step 1: I create FacebookApp_B, define PackageName, ClassName, turn on (Yes) feature Single Sign On , make it to General public status.

Step 2: I use this code to get HashKey and I got it.

try {

    PackageInfo info = getPackageManager().getPackageInfo("<--app Health 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) {

}

Step 3: I change facebook_app_id in Manifest.xml to FacebookApp_B's Id.

Step 4: I build my project to .apk file with file debug.keystore of Education App because I lost Health App's keystore.

Step 5: I setup Health App and click to share a link to facebook. At this time, a confirm dialog is showed on the screen:

AppName would like to access your public profile and friend list

Step 6: I click OK but the ShareDialog is not showed.

Everything works right with FacebookApp_A but not with FacebookApp_B and I don't know what I had missed.

I want show the ShareDialog like using FacebookApp_A.

Thank you very much,

检查您在Android应用程序中共享的Facebook应用程序是否不在沙盒模式下。

If you've created a new facebook app then you also have to generate the hashKey as well. Once you have get the hash key then insert in the facebook app settings. To generate the hash key properly please follow the steps in facebook developer guide.

Facebook Developer Guide

The below code snippet is taken from the facebook developer guide section [4]

public void printHashKey() {

   // Add code to print out the key hash
    try {
        PackageInfo info = getPackageManager().getPackageInfo("com.facebook.samples.hellofacebook", 
                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) {
}

Insert the generated hashKey in the facebook app settings as shown below:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM