如何检测用户取消共享时,使用fb.ui
How to detect user cancelled share when using fb.ui
我使用这里提供的文档和下面的代码。正确弹出共享对话框。问题是,我无法区分用户在对话框中采取的"取消"answers"发布"动作。我想这应该是回应的一部分。
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
对象中有一些信息可以用来确定对话框是否被取消。
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}"}
我想你可以像这样检查cancellaction:
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
这是有意劝阻开发人员不要将发布作为一种控制机制。这应该由用户自己决定是否发布,而不应该是应用程序的要求。
使用"feed"方法代替"share"方法,这样就不需要应用程序的许可来获取响应。
FB.ui({
method: 'feed',
caption: 'My Caption',
link: 'http://www.google.com/'
}, function(response) {
if (response && response.post_id) {
alert('Thank you for sharing!');
} else {
alert('You have cancelled the share.');
}
});
我也有响应函数的问题,我目前正在编码并试图使用fb。UI
return FB.ui({
method: 'share',
href: this.shareUrl,
hashtag: "myHashTag",
quote: "myQuote"
}, function(res) {
console.log("res = ", res);
console.log("res? = ", res != null);
return App.vent.trigger("FBShareView:cancelled");
});
我发现,在一个成功的共享,res是一个空数组和res != null是真
我发现对于取消场景,res是未定义的。
我希望看到res作为一个带有error_message的对象,如下所示:https://developers.facebook.com/docs/sharing/reference/share-dialog
你能告诉我哪里出了问题吗?
相关文章:
- 使用闭包共享构造函数参数
- 使用服务(AngularJS)在控制器之间共享数据
- LinkedIn共享链接图片未使用自定义url更新
- 使用Angularjs在两个不同页面的控制器之间共享数据
- 使用共享工具提示时,单击Highcharts柱形图会返回不正确的序列索引
- 在angularJS中使用模态窗口时,在控制器之间共享对象数组
- 在新表单上使用JavaScript创建多个共享点项目,但将下一页加载延迟到全部创建
- 使用php共享facebook
- 如何使用Windows Phone在IE上禁用上下文菜单(保存和共享照片)
- 如何使用angularJS在多个项目之间共享代码
- 使用NodeJS与客户端共享变量
- 使用ui.grid与cellTemplate共享$scope
- 使用动态og标签进行测试的facebook共享按钮
- Highcharts:如何使用共享一些配置部件的图表进行DRY
- Facebook共享按钮不;在使用Javascript和Ajax的Webmethod中似乎不起作用
- 如何使用共享按钮将所有内容对齐到一行来解决问题
- 如何使用javascript重新填充Facebook共享对话框
- 检查用户在使用传单时是否共享位置's locate()
- JavaScript-使用sessionStorage保存文档之间共享的复选框状态
- GAS:如何允许其他人在不共享代码的情况下使用您的库