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

发布于 2024-11-04 19:48:40 字数 1015 浏览 0 评论 0原文

我目前有以下方法,它创建一个“共享网址”,本质上是插入到应用程序内的 onclick="" 中的代码。

问题是,现在我们不能再拥有 Facebook FBML 应用程序,只能拥有 iframe - 我现在需要包含一个库才能使其工作吗?或者我应该更改代码,我已经用谷歌搜索过,但答案普遍没有结论性或回溯以强制其工作。

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

谢谢大家! :)

I currently have the following method which creates a "share url" essentially the code to insert into an onclick="" within the app.

The problem is that now we can no longer have Facebook FBML applications, only iframe - is there a library I now need to include to make this work? Or should I be changing the code, I have Googled but answers are widely inconclusive or backhacks to force it to work.

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

Thanks all! :)

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

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

发布评论

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

评论(1

二手情话 2024-11-11 19:48:40

要使共享弹出窗口出现在您的 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>

To make a share popup appear from within your facebook app, you have to use the Javascript SDK

you can do this:

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