FBML 墙贴,点击图像或按钮

发布于 2024-10-16 02:46:04 字数 1228 浏览 4 评论 0原文

我正在使用 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>

当我单击图像时,它应该打开一个弹出窗口“发布到墙上”或“发布到您朋友的墙上”以及相应的图像 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. 如果我使用 发布到朋友的留言墙上,我该怎么办?

I'm creating one facebook application with FBML. What I want is:
I have several images like,

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

While I click on the image it should open one popup "post to wall" or "Post to your Friend's wall" with the corresponding image My_Img_Url_n.jpg.

I can use FBML share button like:

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:
I can call 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>

Now the questions are:

  1. If I click on any image it will call either METHOD-1 or METHOD-2 and it will popup with that image. How can I do that?
  2. If I use <fb:multi-friend-input /> for posting to friend's wall, How can I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅语花开 2024-10-23 02:46:04

我会选择选项 2,因为 FBML 很快就会被弃用 (https://developers.facebook.com/docs/reference/fbml/)。

总而言之,初始化 JS SDK,确保您的用户已登录,然后使用新函数包装 FB.ui 调用。然后将图像以 HTML 格式写入页面,并分配单击事件来调用新的 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/文档/参考/javascript/

I would go with option 2 as FBML is going to be deprecated soon (https://developers.facebook.com/docs/reference/fbml/).

To sum up, initialize the JS SDK, make sure that your user is logged in and then wrap the FB.ui call with a new function. Then write out your images to the page in HTML and assign the click event to call your new Javascript function.

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

This example will post to the users wall. If you want to post to another users wall, you'll first need to grab the current users friends IDs with FB.api('me/friends', myGreatCallback) (see https://developers.facebook.com/docs/reference/javascript/FB.api/) and then pass this into postToWall()

I wrote this without trying to run it, let me know if you run into any any errors ;). You can find more information on the Facebook JS SDK at: https://developers.facebook.com/docs/reference/javascript/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文