我正在尝试创建一个Facebook Connect应用程序,在页面内使用Facebook的Javascript API(通过FBMLPopupDialog)显示好友邀请对话框。
问题在于,要显示好友邀请对话框,您需要使用多好友表单,该表单需要一个action="url"属性,表示用户完成或跳过表单时重定向页面的URL。问题是,我想关闭FBMLPopupDialog(与用户只是单击弹出对话框上的“X”按钮相同的行为)。我最好的办法就是将用户重定向回他们所在的页面,基本上是重新加载,但他们会丢失所有AJAX / Flash应用程序状态。
我想知道是否有任何Facebook Connect开发人员遇到过这个问题,并且有一种简单地在网站中显示好友邀请“lightbox”对话框的方法,他们不希望在用户完成后“刷新”或“重定向”。
Facebook Connect JS API提供了FB.Connect.inviteConnectUsers,它提供了一个很好的对话框,但仅连接已经连接Facebook账户的您应用程序中的现有用户。
http://bugs.developers.facebook.com/show_bug.cgi?id=4916
function fb_inviteFriends() {
//Invite users
log("Inviting users...");
FB.Connect.requireSession(
function() { //Connect succes
var uid = FB.Facebook.apiClient.get_session().uid;
log('FB CONNECT SUCCESS: ' + uid);
//Invite users
log("Inviting users...");
//Update server with connected account
updateAccountFacebookUID();
var fbml = fb_getInviteFBML() ;
var dialog = new FB.UI. FBMLPopupDialog("Weblings Invite", fbml) ;
//dialog.setFBMLContent(fbml);
dialog.setContentWidth(650);
dialog.setContentHeight(450);
dialog.show();
},
//Connect cancelled
function() {
//User cancelled the connect
log("FB Connect cancelled:");
}
);
}
function fb_getInviteFBML() {
var uid = FB.Facebook.apiClient.get_session().uid;
var fbml = "";
fbml =
'<fb:fbml>\n' +
'<fb:request-form\n'+
//Redirect back to this page
' action="'+ document.location +'"\n'+
' method="POST"\n'+
' invite="true"\n'+
' type="Weblings Invite"\n' +
' content="I need your help to discover all the Weblings and save the Internet! WebWars: Weblings is a cool new game where we can collect fantastic creatures while surfing our favorite websites. Come find the missing Weblings with me!'+
//Callback the server with the appropriate Webwars Account URL
' <fb:req-choice url=\''+ WebwarsFB.WebwarsAccountServer +'/SplashPage.aspx?action=ref&reftype=Facebook' label=\'Check out WebWars: Weblings\' />"\n'+
'>\n'+
' <fb:multi-friend-selector\n'+
' rows="2"\n'+
' cols="4"\n'+
' bypass="Cancel"\n'+
' showborder="false"\n'+
' actiontext="Use this form to invite your friends to connect with WebWars: Weblings."/>\n'+
' </fb:request-form>'+
' </fb:fbml>';
return fbml;
}