使用 fb.ui 时如何检测用户取消共享

2024-05-22

我正在使用提供的文档here https://developers.facebook.com/docs/sharing/reference/share-dialog使用以下代码。共享对话框正确显示。问题是我无法区分用户在对话框中执行的“取消”和“发布”操作。我想这将是回应的一部分。

FB.ui({
    method: 'share',
    href: 'https://developers.facebook.com/docs/',
}, function(response){
    if (response && !response.error_code) {
        console.log(response);
    } else {
        alert('Error while posting.');
    }
});

编辑:控制台的输出不提供任何了解的方式

Cancel - Object {e2e: "{"submit_0":1401181811121}"} 
Post - Object {e2e: "{"submit_0":1401181815112}"} 

我对此进行了测试,显然其中有一些信息response您可以使用该对象来确定对话框是否被取消。

Code

FB.ui({
    method: 'share',
    href: 'https://developers.facebook.com/docs/'
}, function(response){
    if (response && !response.error_code) {
        console.log("OK: "+JSON.stringify(response));
    } else {
        console.log("Not OK: "+JSON.stringify(response));
    }
});

取消时的输出:

{error_code: 4201, error_message: "User+canceled+the+Dialog+flow", e2e: "{"submit_0":1401188820613}"} 

所以,我想你可以像这样检查取消操作:

FB.ui({
    method: 'share',
    href: 'https://developers.facebook.com/docs/'
}, function(response){
    if (response && !response.error_code) {
        console.log("OK: "+JSON.stringify(response));
    } else if (response && response.error_code === 4201) { //Cancelled
        console.log("User cancelled: "+decodeURIComponent(response.error_message));
    } else {
        console.log("Not OK: "+JSON.stringify(response));
    }
});

很遗憾,FB.Events.subscribe()不提供取消此对话框的事件:https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/v2.0 https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/v2.0

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 fb.ui 时如何检测用户取消共享 的相关文章