Facebook Android SDK integration

2019-07-28 05:22发布

问题:

I encounter a problem when integrating Facebook SDK to android. Basically, I have successfully integrated to my phone. I followed the tutorial to add the hash key with 30 lenght of string. Then testing on my device it works fine.

However, when I ask my friend to try my app, he reported that he could not do anything with the sharing facebook stuff. Here is what the chunk of code to do the sharing stuff:

/**
 * Publish Feed Dialog
 * @param current
 * @param title
 * @param caption
 * @param description
 * @param link
 * @param pictureUrl
 */
public static void publishFeedDialog(final Activity current, final String title, final String caption, final String description, final String link, final String pictureUrl) {
    // start Facebook Login
    Session.openActiveSession(current, true, new Session.StatusCallback() {

        // callback when session changes state
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            if (session.isOpened()) {
                Bundle params = new Bundle();
                params.putString("name", title);
                params.putString("caption", caption);
                params.putString("description", description);

                if (link != null) params.putString("link", link);
                if (pictureUrl != null) params.putString("picture", pictureUrl);

                WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(current, Session.getActiveSession(), params))
                        .setOnCompleteListener(new OnCompleteListener() {

                            @Override
                            public void onComplete(Bundle values, FacebookException error) {
                                if (error == null) {
                                    // When the story is posted, echo the
                                    // success
                                    // and the post Id.
                                    final String postId = values.getString("post_id");
                                    if (postId != null) {
                                        Toast.makeText(current, "Posted", 2000).show();
                                    } else {
                                        // User clicked the Cancel button
                                        Toast.makeText(current, "Publish cancelled", 2000).show();
                                    }
                                } else if (error instanceof FacebookOperationCanceledException) {
                                    // User clicked the "x" button
                                  Toast.makeText(current, "Publish cancelled", 2000).show();
                                } else {
                                    // Generic, ex: network error
                                  Toast.makeText(current, "Error posting story", 2000).show();
                                }
                            }

                        }).build();
                feedDialog.show();
            }
        }
    });
}

I only use this chunk of code to publish feed dialog. and for the facebook app settings:

  1. package Name -> com.ImranQureshi.HadithPro
  2. class Name -> com.imran.hadith.MainActivity
  3. Key Hashes -> t8tk8tRXcAXxnn4U0mRcCBSqHf
  4. Facebook Login -> enabled
  5. Deep Linking -> disabled

If I dont use key hashes, I will get exception there, it says: com.facebook.http.protocol.ApiException: Key hash t8tk8tRXcAXxnn4U0mRcCBSqHf does not match any stored key hashes

This makes sense because the hash is not there. When I put that hash key, it works in my real device, BUT not in my friend's device. Can you advice what is wrong?