我正在使用伪造的facebook api打开提要对话框,将图像发布到用户墙上。如果用户单击"取消"而不是"共享",仍会触发成功回调。如果用户单击关闭 (x) 按钮,则会正确触发错误回调。
forge.facebook.ui(
{
method: 'feed',
link: link,
picture: model.get('file').url,
name: name,
caption: caption,
description: 'Lorem Ipsum'
},
function(response) {
// Called when user clicks cancel.
forge.notification.create(
'Great!',
'Item has been posted to your wall',
function() {
},
function(error) {
forge.logging.error(JSON.stringify(error));
}
);
},
function (e) {
// Called when user closes dialogue but not on cancel.
forge.logging.info('facebook failed: ' + JSON.stringify(e));
}
);
我倾向于同意这是意外行为 - 但是它在几个Facebook提供的SDK中是一致的,并且已经有一段时间了,所以我们按原样传递了它。
如果用户点击对话框左上角的x
,则会调用错误回调。如果用户取消对话框,将使用 {}
作为回调参数调用成功回调。
我建议使用以下方法检查这种情况:
forge.facebook.ui({
method: 'feed',
link: link,
},
function (response) {
if (JSON.stringify(response) === "{}") {
handleCancel();
} else {
handleSuccess(response);
}
}
function (error) {
handleError(error);
}
);