javascript - Check if user posted (or cancelled) sharing to Facebook in Share Dialog using FB.ui - Stack Overflow

I'm using a share dialog and I want something to occur after the user posts something to hisher t

I'm using a share dialog and I want something to occur after the user posts something to his/her timeline. Right now I'm using:

function shareToFB(myName, myLink) {
    $('.overlay-bg').hide();
    FB.ui({
        method: 'share',
        href: myLink,
        name: myName
    }, function(response) {
        if (response && !response.error_code) {
            alert("Something");
        } else {
            alert("Error");
        }
    }
    );
}

But this causes "Something" to show up even when the user cancels posting. Is there any way I can find if the user has posted the message to his/her timeline without requiring any permissions. I won't mind if this requires me to use a different method of sharing (like a feed dialog).

I'm using a share dialog and I want something to occur after the user posts something to his/her timeline. Right now I'm using:

function shareToFB(myName, myLink) {
    $('.overlay-bg').hide();
    FB.ui({
        method: 'share',
        href: myLink,
        name: myName
    }, function(response) {
        if (response && !response.error_code) {
            alert("Something");
        } else {
            alert("Error");
        }
    }
    );
}

But this causes "Something" to show up even when the user cancels posting. Is there any way I can find if the user has posted the message to his/her timeline without requiring any permissions. I won't mind if this requires me to use a different method of sharing (like a feed dialog).

Share Improve this question asked Oct 16, 2014 at 17:32 TheSlimyDogTheSlimyDog 3145 silver badges10 bronze badges 1
  • A part of my program is supposed to sort the items of a list based on how many shares each one got. I can check the number of successful responses but if someone clicks cancel, then that can't really be counted as a share (for obvious reasons). – TheSlimyDog Commented Oct 17, 2014 at 18:06
Add a ment  | 

2 Answers 2

Reset to default 4

Use Feed Dialog instead.

Despite its UI being ugly, successful sharing via Feed Dialog will return a response object like {post_id: "10206702999763274_10206703017843726"} regardless of user authenticating your Facebook app or not, while pressing cancel will return a null and closing popup will return undefined.

You can test this behaviour by going to your normal Facebook user profile settings and try removing your app from allowed list.

This is in contrast to the Share Dialog, which, if your app has not been authenticated by user, will return an empty response object {} regardless of successful sharing or not.

Furthermore, if you use the direct url redirect method instead of js SDK, when the user press cancel on the share page you will receive a GET parameter error_code and error_message appended to your redirect target.

[From December 2015] => Use Feed Dialog or the Share Dialog to access the post ID in the response. To achieve this the user must have logged into your app and granted it publish_actions. https://developers.facebook./docs/sharing/reference/share-dialog#response


NOTE: This is true for the time of this writing (API v2.3). However as Facebook is notorious for breaking API behaviour, you should test it yourself first.

According to the docs, the response is the object_id of the posted entry - and it is only filled if the user authorized the App. Meaning, you can´t detect if a user really posted something if the user is not authorized.

Source: https://developers.facebook./docs/sharing/reference/share-dialog

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742288907a4415828.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信