3
votes

I'm developing an Android application which should allow a user to share a post on Facebook. For statistics, I would like to know if the user has successfully shared a post or decided to cancel.

Question: Is there a way to check if post was successfully shared using ShareDialog from Facebook SDK 4.5, without publish_action permission?

ShareDialog opens Facebook App share dialog and if the share was successful, onSuccess method in the callback function is called (or onCancel if user cancels the share dialog). The problem is when user doesn't have a Facebook App installed on his device. Then ShareDialog falls back to default browser for sharing, but callback function onSuccess method is always executed in that case, even if user has clicked on the cancel button!

My current code looks like this:

FacebookCallback<Sharer.Result> shareCallback = new FacebookCallback<Sharer.Result>() {
    @Override
    public void onCancel() {
        Log.d(LOG_TAG, "fb SHARE canceled");
    }

    @Override
    public void onError(FacebookException error) {
        Log.d(LOG_TAG, "fb SHARE error");
    }

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

        String postId = result.getPostId();
        if (postId != null)
        {
            // record successful FB share
            Log.d(LOG_TAG, "fb SHARE success");
        }
    }
}

FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
shareDialog = new ShareDialog(this);
shareDialog.registerCallback(callbackManager, shareCallback);

This code works fine, but it requires publish_actions permission to check postId. Is there some other way to check if sharing was successful, without requiring additional (publish_actions) permissions from Facebook (because that's just too painful)?

1
i believe that´s not possible, because it would be easy to abuse it for incentivizing - which is not allowed.andyrandy
let us know if you have found an updateNilabja
@Nilabja Unfortunately not. It seem that browser share dialog always returning to onSuccess is not a bug, but a feature. I'll have to write my code to use publish_actions (I'm still not sure how to trigger publish_actions).cakan
just leave a comment here when you succeed @cakanNilabja
Any update on this?Vivek Sinha

1 Answers

2
votes

There is a way around this problem. Thing is postId is always null when you share with Facebook's app. PostId gets through to your onSuccess callback when you share without FB app. The solution is to force your application to use web feed and not FB app for sharing:

shareDialog.show(linkContent, ShareDialog.Mode.FEED);