【发布时间】:2011-06-01 12:33:02
【问题描述】:
我正在尝试创建一个 Facebook 应用程序,该应用程序使用 Facebook 的 Javascript API (FB.ui) 在应用程序中显示朋友邀请对话框。
为此,我关注了this tutorial
我有两个问题:
-
我在请求表单中输入的操作 url 是“http://apps.facebook.com/appname/post_invite.php” 但我看到帖子后的 iframe 来源是“http://example.com/post_invite.php” 当此 iframe 尝试执行以下操作时: parent.closeInviteWidget(); 我收到一条错误消息:
“http://example.com>(document.domain 尚未设置)从 http://apps.facebook.com>(document.domain=http://facebook.com>)获取属性 Window.closeInviteWidget 的权限被拒绝。”
请求表单中的跳过按钮会在新窗口(新浏览器选项卡)中打开操作 url,而不是像邀请按钮那样发布到自身。
我该如何解决这些问题?
-------- 更新: ------------- -------
我已经尝试按照 ifaour 所说的去做,并将代码更改为:
function inviteFriends(user_name, category_id, category_name)
{
url = appBaseUrl + "/index.php?category_id=" + category_id;
req = "<fb:req-choice url='" + url + "' label='Authorize My Application' />";
content = user_name + " opened a new category called " + category_name + ". " + req;
action = 'post_invite.php';
fbmi_text = '<fb:request-form action="' + action + '" target="_self" method="post" invite="true" type="Invite" content="' + content + '" <fb:multi-friend-selector showborder="false" actiontext="Invite yor friends" email_invite="false" import_external_friends="false" /> </fb:request-form>';
FB.ui({
method:'fbml.dialog',
width:'750px',
fbml:fbmi_text
});
}
当我使用 FireBug 并查看邀请表单时,它看起来像这样:
<form id="req_form_4d20682f73ddb6e71722794" content="I've opened a new category called dsfsd. <fb:req-choice url='http://apps.facebook.com/appname/index.php?category_id=60' label='Authorize My Application' /> type="Invite" invite="true" method="post" target="_self" action="http://apps.facebook.com/appname/post_invite.php">
...
</form>
但我仍然遇到同样的错误:
http://example.com(document.domain 尚未设置)从http://apps.facebook.com(document.domain=http://facebook.com)获取属性 Window.closeInviteWidget 的权限被拒绝...
这是我的应用设置(我添加了空格,因为我无法添加更多链接):
网址:http://appname.example.com/
画布页面:http://apps.facebook.com/appname/
画布网址:http://appname.example.com/
画布 FBML/iframe : iframe
授权后重定向 URL:http://apps.facebook.com/appname/
【问题讨论】: