如何在iframe Facebook应用程序中创建“共享”弹出窗口

时间:2011-05-04 09:00:11

标签: php javascript facebook fbml fbjs

我目前有以下方法创建一个“共享网址”,主要是在应用程序中插入onclick =“”的代码。

现在的问题是,现在我们再也无法拥有Facebook FBML应用程序,只有iframe - 我现在需要包含一个库才能使其工作吗?或者我应该更改代码,我已经使用Google搜索,但答案是广泛的不确定或后退,以迫使它工作。

public function getShareUrl($title, $url, $caption, $description, $imageSrc, $shareButtonText = 'Share your thoughts!')
{
    $url .= "var attachment = {
                    'name':'$title',
                    'href':'$url',
                    'caption':'$caption',
                    'description':'".$description."',
                    'media':[{
                        'type':'image',
                        'src':'$imageSrc',
                        'href':'$url'
                    }]
                };
                var actionLinks = [{
                    'text':'Join the app now',
                    'href':'$url'
                }];
                Facebook.streamPublish('', attachment, actionLinks, null, '$shareButtonText');
                return false;";
    return $url;
}

谢谢大家! :)

1 个答案:

答案 0 :(得分:11)

要在Facebook应用中显示共享弹出窗口,您必须使用Javascript SDK

你可以这样做:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
  <head>
<title></title>
</head>
  <body>
  <div id="fb-root"></div>
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
  FB.init({
   appId  : 'yourappid',
   status : true,
   cookie : true,
   xfbml  : true 
  });
</script>
<script type="text/javascript">
  function streamPublish(name, description, hrefTitle, hrefLink, userPrompt, imageSrc, imageUrl) {
      FB.ui({
          method: 'stream.publish',
          message: '',
          attachment: {
              media: [{
                  type: 'image',
                  src: imageSrc,
                  href: imageUrl
              }],
              name: name,
              caption: '',
              description: (description),
              href: hrefLink
          },
          action_links: [{
              text: hrefTitle,
              href: hrefLink
          }],
          user_prompt_message: userPrompt
      }, function (response) {
          // do something when you have posted
      });
  }

  function publishStream() {
      streamPublish("Stream Publish", 'sample publish', 'do something cool', 'http://example.com', "My fb app", 'http://bit.ly/AJTnf', 'http://bit.ly/hifZk');
  }
 </script>
<p>Stream Publish Test</p>
<a href="#" onclick="publishStream(); return false;">Post a story</a>
  </body>
</html>