10

Facebook の Javascript API ( FBMLPopupDialogを使用)を使用して、ページ内に友達招待ダイアログを表示する Facebook Connect アプリケーションを作成しようとしています。

問題は、あなたが使用する友人招待ダイアログを表示することですユーザーがフォームを完了またはスキップしたときにページをリダイレクトする URL を表す action="url" 属性を必要とするマルチフレンド フォーム。問題は、FBMLPopupDialog (ユーザーがポップアップ ダイアログの [X] ボタンを押した場合と同じ動作) を閉じたいことです。私ができる最善の方法は、ユーザーを基本的にリロードしていたページにリダイレクトすることですが、AJAX/Flash アプリケーションの状態はすべて失われます。

Facebook Connect 開発者がこの問題に遭遇し、ユーザーが終了したときに「更新」または「リダイレクト」したくない、Web サイト内に友人招待の「ライトボックス」ダイアログを表示するだけの良い方法があるかどうか疑問に思っています。 .

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

5 に答える 5

8

誰かが 2011 年にこのようなものを探す場合、ここにリンクがあります: http://developers.facebook.com/docs/reference/dialogs/requests/で、アプリケーション リクエストを送信するために必要なコードは次のとおりです。

FB.ui({method: 'apprequests', message: 'A request especially for one person.', data: 'tracking information for the user'});
于 2011-08-31T20:38:44.200 に答える
2

これが私がそれを解決した方法です

私のJS / FBML(target="_self"マルチフレンドセレクターの属性に注意してください):

 var inviteDialog;    // Keep a reference for the popup dialog

 function makeInviteForm() {

  // Set up request form elements here

  var fbml = '';
  fbml += '<fb:fbml>';
  fbml += '   <fb:request-form type="' + requestType + '" content="' + requestContent + '" action="' + actionUrl + '" method="post" >';
  fbml += '       <fb:multi-friend-selector target="_self" exclude_ids="" max=' + maxFriends + ' cols="4" rows="3" showborder="false" actiontext="Invite friends!" />';
  fbml += '   </fb:request-form>';
  fbml += '</fb:fbml>';

  inviteDialog = new FB.UI.FBMLPopupDialog(title, fbml);

 }

私のPHP:

 <?php
 // Do processing here
 ?>
 <script type="text/javascript">
 parent.inviteDialog.close();    // You could make this call a function that does additional processing if you want
 </script>
于 2010-09-28T01:31:25.280 に答える
1

このファイル xd_receiver.html がどこかにある場合は、次のようにサイトの完全な URL を使用して xd_receiver.html ファイルへのパスを正しく指定していることを確認してください。

http://www.yoursite.com/xd_receiver.html

于 2009-11-23T12:50:34.800 に答える
1

request-form 要素で target="_self" を指定すると (Domenic が示唆するように、フレンド セレクターではなく)、応答 URL が iframe に読み込まれ、ページ全体がリロードされないことがわかりました。

したがって、この時点で独自のプロンプトをロードしてウィンドウを閉じるか、もう少し作業を進めて親にメッセージを送信し、iframe 全体を自動的に閉じることができます。

于 2010-12-03T22:23:26.403 に答える
0

アプリについて詳しく説明していただけますか。フラッシュですか?サーバー側で使用しているテクノロジーの種類。PHP を使用している場合は、Jquery ライトボックスまたはスムーズボックスを使用して招待ページをポップアップできます。アプリの残りの部分は FBML ではなく Facebook API を使用していると思っていても、アプリの招待に FBML コードを使用しました。以下は、PHP を使用している場合の例です。PHP を使用していない場合でも、これを使用できます。問題がある場合はお知らせください。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<script type="text/javascript" src="... .... Your stuf here .... title="stylesheet" type="text/css"> </head>
<body>
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>

<? include "my header file was here!"; ?>
<?PHP // Get these from http://developers.facebook.com $api_key = '[api_key]'; $secret = '[secret]';
$app_name = "[Your App name]";
$app_url = "[your canvas page]";
$invite_href = "[put_destination]"; // Rename this as needed require_once '../neo_nosrati/facebook-platform/facebook.php';
/*change accordingly probably something like:../facebook/facebook-platform/php/facebook.php' . THE API Library you downloaded from facebook! */

$facebook = new Facebook($api_key, $secret); $facebook->require_frame();
$user = $facebook->require_login(); if(isset($_POST["ids"])) { echo "<center>Thank you for inviting ".sizeof($_POST["ids"])." of your friends on <b><a href=\"http://apps.facebook.com/".$app_url."/\">".$app_name."</a></b>.<br><br>\n"; echo "<h2><a href=\"http://apps.facebook.com/".$app_url."/\">Click here to return to ".$app_name."</a>.</h2></center>"; }

else { // Retrieve array of friends who've already authorized the app. $fql = 'SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1='.$user.') AND is_app_user = 1'; $_friends = $facebook->api_client->fql_query($fql); // Extract the user ID's returned in the FQL request into a new array. $friends = array(); if (is_array($_friends) && count($_friends)) { foreach ($_friends as $friend) { $friends[] = $friend['uid']; } }

// Convert the array of friends into a comma-delimeted string. $friends = implode(',', $friends); // Prepare the invitation text that all invited users will receive.
$content = "<fb:name uid=\"".$user."\" firstnameonly=\"true\" shownetwork=\"false\"/> has started using <a href=\"http://apps.facebook.com/".$app_url."/\">".$app_name."</a>. YOUR MESSAGE. You should definitely try it out!\n". "<fb:req-choice url=\"".$facebook->get_add_url()."\" label=\"Somthing like. Add app!\"/>"; ?> <fb:serverfbml style="width: 750px;"> <script type="text/fbml"> <fb:fbml> <fb:request-form action="<? echo $invite_href; ?>" method="post" type="<? echo $app_name; ?>" content="<? echo htmlentities($content,ENT_COMPAT,'UTF-8'); ?>"> <fb:multi-friend-selector actiontext="Here are your friends who have not added the application yet." exclude_ids="<? echo $friends; ?>" /> </fb:request-form> </fb:fbml> </script> </fb:serverfbml>

<?PHP } ?>
<script type="text/javascript"> FB_RequireFeatures(["XFBML"], function(){ FB.Facebook.init("Secret Api", "../xd_receiver.htm"); }); </script>
</body> </html>

于 2010-05-05T16:49:24.240 に答える