简体   繁体   中英

Facebook SDK for Android 4.1.0 share dialog cancel

I'm implementing Facebook sharing feature in my app. I took the code from the example https://developers.facebook.com/docs/sharing/android (Share Dialog)

FacebookCallback is implementing 3 methods onSuccess, onCancel, onError.

   shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
        @Override
        public void onSuccess(Sharer.Result result) {
            Timber.e("onSuccess " + result.getPostId());
        }

        @Override
        public void onCancel() {
            Timber.e("onCancel");

        }

        @Override
        public void onError(FacebookException e) {
            Timber.e("onError");
        }
    });

I want to know if user cancels share dialog instead of sharing content. But for some reasons onSuccess is called and result.getPostId() is null in both cases if user successfully shares content or cancels dialog. Why onCancel isn't called if user pressed back and why result.getPostId() is null even if post was shared successfully?

You will only get onCancel if the user has authorized your app (ie logged into Facebook via your app).

You will only get the postId if your app also has the publish_actions permission.

See https://developers.facebook.com/docs/android/troubleshooting#onsuccess

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