使用fb.ui时如何检测用户取消的共享 [英] How to detect user cancelled share when using fb.ui

查看:640
本文介绍了使用fb.ui时如何检测用户取消的共享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此处提供的文档,其中包含以下内容码。共享对话框正确出现。问题是我无法区分用户对话框中的取消和发布操作。我想象这将是回应的一部分。

  FB.ui({
method:'share ',
href:'https://developers.facebook.com/docs/',
},function(response){
if(response&&!response.error_code) {
console.log(response);
} else {
alert('发布时出错');
}
});

编辑:从控制台输出不是没有提供任何方式知道

 取消 - 对象{e2e:{submit_0:1401181811121}} 
Post - Object {e2e:{submit_0 :1401181815112}}


解决方案

显然,您可以使用响应对象中的某些信息来确定对话框是否已取消。



代码



  FB.ui({
method:'share',
href:'https://开发人员。 ($)$ {
},function(response){
if(response&&!response.error_code){
console.log stringify(response));
} else {
console.log(Not OK:+ JSON.stringify(response));
}
});

取消时输出:

  {error_code:4201,error_message:User + cancelled + the + Dialog + flow,e2e:{submit_0:1401188820613}} 
/ pre>

所以,我想你可以检查这样的cancelaction:

  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){//已取消
console.log(用户已取消:+ decodeURIComponent(response.error_message));
} else {
console.log(不行:+ JSON.stringify(response));
}
});

不幸的是, FB.Events.subscribe()不提供此对话框可以调用的事件: https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/v2.0


I'm using the documentation provided over here with the following code. The share dialog comes up correctly. The problem is that I'm not able to differentiate between "Cancel" and "Post" actions that the user takes on the dialog. I'd imagine this would be a part of the response.

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.');
    }
});

edit: output from the console isn't doesn't provide any way of knowing

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

解决方案

I tested this, and apparently there's some info in the response object you could use to determine if the dialog was cancelled.

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));
    }
});

Output upon cancellation:

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

So, I guess you could check for cancellaction like this:

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));
    }
});

Unfortunately, FB.Events.subscribe() doesn't offer an Event for the Cancallation of this dialog: https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/v2.0

这篇关于使用fb.ui时如何检测用户取消的共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆