2011-02-06 9 views
2

FBMLを使用して1つのFacebookブックアプリケーションを作成しています。私が欲しいのです: 私はそれが対応する画像My_Img_Url_n.jpgで「あなたのお友達のウォールに投稿」「壁にポスト」または1つのポップアップを開く必要があります画像をクリックしている間、私は画像またはボタンをクリックしてFBML壁柱

<fb:tag name="img"> 
<fb:tag-attribute name="src">http://My_Img_Url_1.jpg</fb:tag-attribute> 
</fb:tag> 
<fb:tag name="img"> 
<fb:tag-attribute name="src">http://My_Img_Url_2.jpg</fb:tag-attribute> 
</fb:tag> 

、のようないくつかの画像を持っています。

私は次のようにFBMLの共有ボタンを使用することができます。

METHOD-1

<fb:share-button class="meta"> 
<meta name="title" content="Image_TITLE"/> 
<meta name="description" content="Image_Descrip"/> 
<link rel="image_src" href="http://My_Img_Url_1.jpg"/> 
<link rel="target_url" href="Some_Target_URL"/> 
</fb:share-button> 

OR、

METHOD-2: 私はFBを呼び出すことができます。UI

<script> 
FB.init({ 

appId:'111111111111111', cookie:true, 

    status:true, xfbml:true 
}); 

FB.ui({ method: 'feed', 
name: '', 
link: '', 
picture: 'http://My_Img_Url_1.jpg' 
}); 
</script> 

質問は次のとおりです:

  1. イメージをクリックすると、METHOD-1またはMETHOD-2が呼び出され、そのイメージがポップアップします。どうやってやるの?
  2. <fb:multi-friend-input />を友人の壁に投稿する場合はどうすればよいですか?
+0

です。これを実装するためにPHPを使用できます... – psaha

答えて

0

すぐにFBMLが廃止されるため、私はオプション2を使用します(https://developers.facebook.com/docs/reference/fbml/)。

要約すると、JS SDKを初期化し、ユーザーがログインしていることを確認してから、FB.ui呼び出しを新しい関数でラップします。次に、イメージをHTMLでページに書き出し、clickイベントを割り当てて新しいJavascript関数を呼び出します。

<div id="fb-root"></div> 
<script src="http://connect.facebook.net/en_US/all.js"></script> 
<script> 
    // Initialize the Facebook Javascript SDK 
    FB.init({ 
    appid: 'YOUR_APP_ID_HERE', 
    status: true, 
    cookie:true 
)}; 

    //Let's grab the userId for the user that is logged in 
    //If you user is not logged in, redirect or prompt them to login/install the app. 
    var userId = null; 
    FB.getLoginStatus(function(response) { 
    if (response.session) { 
     uid = response.session.uid; 
    } 
    else { 
     //Redirect or prompt to login with FB.login(), etc. 
     //https://developers.facebook.com/docs/reference/javascript/FB.login/ 
    } 
    }); 

    //Create your function to post to the users wall 
    function postToWall(userId, imageURI, linkURI, name) { 
    FB.ui({ method: 'feed', 
     to: userId, 
     name: name, 
     picture: pictureURI, 
     link: linkURI 
    }, postToWallCallback); 
    } 

    //Create your callback function, this will be called when the user sends or closes the 
    //Feed Dialog 
    var postToWallCallback = function(response) { 
    //For testing, let's alert out the contents of the response 
    var responseStr = ''; 
    for(var item in response) 
     responseStr += item + "=" + response[item] = "\n"; 

    alert(responseStr); 
    } 
</script> 

<!-- Now print your image to the page and wrap it in an anchor tag that calls your Javascript function --> 
<a href="#" onclick="postToWall(uid, 'my_great_image.jpg', 'my_great_site.jpg', 'My Great Name');"> 
    <img src="my_great_image.jpg" /> 
</a> 

この例は、ユーザーの壁に投稿されます。別のユーザーの壁に投稿したい場合は、FB.api( 'me/friends'、myGreatCallback)(https://developers.facebook.com/docs/reference/javascript/FB.api/)で現在のユーザーのフレンドIDを取得し、postToWallに渡します。

これを実行しようとせずに書きましたが、何かエラーが発生した場合はお知らせください。 Facebook JS SDKに関する詳細は、https://developers.facebook.com/docs/reference/javascript/

関連する問題