通过单击图像或按钮FBML wallpost

时间:2011-02-06 07:20:00

标签: facebook fbml

我正在用FBML创建一个facebook应用程序。我想要的是: 我有几个像,

<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>

当我点击图片时,它应该打开一个弹出“post to wall”或“Post to your Friend's wall”,并显示相应的图片My_Img_Url_n.jpg。

我可以使用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>

或,

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 />张贴到朋友的墙上,我该怎么办?

1 个答案:

答案 0 :(得分:0)

我会选择2,因为FBML很快就会被弃用(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)获取当前用户的朋友ID(参见https://developers.facebook.com/docs/reference/javascript/FB.api/),然后将其传递给postToWall( )

我写了这个没有试图运行它,如果你遇到任何错误,请告诉我;)。您可以在以下网址找到有关Facebook JS SDK的更多信息:https://developers.facebook.com/docs/reference/javascript/