Search code examples
androidfacebookfacebook-sdk-4.0

Android Facebook SDK - Share dialog does not respond to cancel callback


I'm working with Facebook sdk 4.0 on my android app and I found this problem:

-when I share a post, I can see the facebook interface and I can post it and cancel it perfectly. I registered the callbacks, but if I press the cancel button, the onCancel callback is not called, the post is not published, but the onSuccess callback is called. However, if I touch the close button, everything works ok.

Here is my code:

 private void fbOnShare(){

    ShareLinkContent shareContent = new ShareLinkContent.Builder()
            .setContentTitle("The Simpson!")
            .setContentUrl(Uri.parse("http://www.foxplay.com/ar/show/6980-los-simpson?gclid=CPa-7N-y7MUCFYMSHwodNLYAKQ"))
            .build();


    this._btnShare = (ShareButton)findViewById(R.id.share_button);
    this._btnShare.setShareContent( shareContent );


    _btnShare.registerCallback( this._fbCallbackManager, new FacebookCallback<Sharer.Result>() {
        @Override
        public void onSuccess(Sharer.Result result) {

            Log.v("MyApp", "Share success!"); //Showed if I press the share or the cancel button

        }

        @Override
        public void onCancel() {
            Log.v("MyApp", "Share canceled"); //Only showed when I press the close button
        }

        @Override
        public void onError(FacebookException e) {
            Log.v("MyApp","Share error: " + e.toString());
        }

    });
}

The _fbCallbackManager is created in another method that initializes everything in the onCreate method from the activity.

https://i.sstatic.net/MGoeZ.jpg

The "Cancelar" button only respond to the onSuccess callback inspite of does not post the share content. The "close" button works ok.


Solution

  • According to THIS it is not a bug and it should stay that way.

    The only way to know if the user accepted the publishing is to check for the postID on the result.

    You will only have a postID if the user didn't cancel AND if the user is logged in to your app AND it has publish permissions. Otherwise it will always be null.

    Yeah I know, it sucks.