3

I am using Facebook Android SDK version 4.25 and ShareLinkContent, ShareDialog for posting to Facebook on user behalf using my app.

This is the dialog which opens when user clicks my app's share functionality

enter image description here

There are two cross icons in sharedialog as you can see in the image. When i am clicking upper cross icon, sharedialog closes and onCancel callback is called.

Problem is when i am clicking lower cross icon onSuccess callback is being called same when i am clicking Post button. I want to give user some points when he shares post to Facebook. But i am getting success callback on lower cross icon as well. What to do? Thank You.

This is the callback code i am using :-

shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {

    @Override
    public void onSuccess(Sharer.Result result) {

            Log.e(LOG_TAG, "Facebook share success " + result.getPostId());

    }

    @Override
    public void onCancel() {

            Log.e(LOG_TAG, "Facebook share cancel");

    }

    @Override
    public void onError(FacebookException error) {

            Log.e(LOG_TAG, "Facebook share error");

    }

});
Navneet Krishna
  • 5,009
  • 5
  • 25
  • 44

1 Answers1

1

When you click the upper cross, you are actually closing your own dialog box, that calls onCancel. But when click on the lower cross, it actually is in facebook view. So the callback is returned from facebook not your dialog. Try:

@Override
public void onSuccess(Sharer.Result result) {
   Log.e(LOG_TAG, "Facebook share success " + result.getPostId());
   //Notice this post id in both, cross click and when the status is updated successfully
   //So, if you don't get a valid post id returned, you can count it as a cancel.
}
Mukarram Ali
  • 387
  • 5
  • 24
  • result.getPostId() is coming null for both cases lower cross click and post button click. –  Sep 21 '17 at 11:23
  • Are you able to post anything on facebook through this. May be the problem is with your facebook integration, because if the post is successfully updated, you would have been getting a defined postid. – Mukarram Ali Sep 22 '17 at 09:31
  • yes the post to Facebook is showing in timeline successfully. I have tested with another Facebook account as well. –  Sep 22 '17 at 09:50
  • @MukarramAli Brother I am facing the same problem do you have the solution ? – Ravind Maurya Jun 17 '18 at 16:09