如何在 iframe Facebook 应用程序中使用 FB.Connect.streamPublish?

发布于 2024-08-17 20:48:50 字数 607 浏览 3 评论 0原文

我正在制作一个简单的基于 iframe 的 Facebook 应用程序。我有以下代码来调整 iframe 的大小:

FB_RequireFeatures(["Connect"], function(){
  FB.XdComm.Server.init('/xd_receiver.htm');
  FB.CanvasClient.startTimerToSizeToContent();
  FB.CanvasClient.syncUrl();
});

我想添加一个链接,该链接将显示一个弹出窗口,该弹出窗口将允许用户将应用程序定义的图像/链接发布到用户的墙上。为了让事情最初正常工作,我尝试在点击事件上使用以下代码:

FB.Connect.streamPublish('');

但是,什么也没有发生。我尝试添加:

FB.init(<?=API_KEY?>, '/xd_receiver.htm');

都在 FB_RequireFeatures 函数内,在它之前,在它之后......没有运气。什么也没发生。不会抛出任何错误。没有什么。有什么想法吗?

I'm making a simple iframe-based facebook app. I have the following code to size my iframe:

FB_RequireFeatures(["Connect"], function(){
  FB.XdComm.Server.init('/xd_receiver.htm');
  FB.CanvasClient.startTimerToSizeToContent();
  FB.CanvasClient.syncUrl();
});

I want to add a link that will display a popup which will allow the user to post an app-defined image/link to the user's wall. To get things working initially, I tried just using the following code on a click event:

FB.Connect.streamPublish('');

However, nothing happens. I've tried adding:

FB.init(<?=API_KEY?>, '/xd_receiver.htm');

both inside the FB_RequireFeatures function, before it, after it... no luck. Nothing happens. No errors are thrown. Nothing. Any ideas?

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

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

发布评论

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

评论(3

秋凉 2024-08-24 20:48:51

检查您是否拥有:(一些来自 http://wiki.developers。 facebook.com/index.php/Connect/Setting_Up_Your_Site#Referencing_Facebook_Connect_on_Your_Site)

  • 创建了 xd_receiver.htm,并且它位于您域的根目录中
  • BODY< 顶部包含了 FeatureLoader.js.php /strong> 您的文档
  • 将问题中的 javascript(例如 FB_RequiresFeatures 等)添加到文档底部

当前在我的应用程序中正常运行的代码示例:

<script type="text/javascript">
   window.onload = function() {
        FB_RequireFeatures(["XFBML", "Connect"], function() {
           FB.Facebook.init("...my api key...","xd_receiver.htm");
           FB.CanvasClient.syncUrl();
        });
   };
</script>

您可以从 FB_RequireFeatures 调用中省略“XFBML”,并且也将路径更改为 xd_receiver.htm,它应该可以正常工作。

此外,请仔细检查应用程序的连接 URL(通过 Facebook 中的开发人员应用程序设置)是否指向 xd_receiver.htm 文件的父级。因此,如果您的应用程序托管在 http://www.mydomain.com 上,那么请查看您的代码示例,您的 xd_receiver.htm 将位于 http://www.mydomain.com/xd_receiver.htm,并且您需要将 http://www.mydomain.com 作为连接 URL。

如果这仍然不起作用,请尝试安装 Firebug (或类似工具)来查看网络流量。当我让它工作时,Facebook Javascript API 会默默地失败,只有通过检查来回的请求,我才发现 Facebook 不喜欢我的 Connect URL。

为了测试它是否全部正常工作,我很想使用

FB.Connect.streamPublish();

您发布的行,因为它应该弹出一个对话框,并且明确给出了一个工作示例。我不确定如果您只传递一个空字符串作为参数会发生什么。

最后,有很多基于 IFrame 的 Facebook 应用程序 - 如果您发现其中一个正在做您喜欢的事情,您可以随时查看他们的 Javascript 以了解他们是如何实现这一目标的。或者换句话说,Facebook 充满了示例 IFrame 应用程序代码。

Check that you have: (some from http://wiki.developers.facebook.com/index.php/Connect/Setting_Up_Your_Site#Referencing_Facebook_Connect_on_Your_Site)

  • Created xd_receiver.htm, and that it is in the root of your domain
  • Included the FeatureLoader.js.php at the top of the BODY of your document
  • Added the javascript in the question (e.g. FB_RequiresFeatures, etc) to the bottom of your document

An example of code that is currently running okay in my app:

<script type="text/javascript">
   window.onload = function() {
        FB_RequireFeatures(["XFBML", "Connect"], function() {
           FB.Facebook.init("...my api key...","xd_receiver.htm");
           FB.CanvasClient.syncUrl();
        });
   };
</script>

You can omit the "XFBML" from the FB_RequireFeatures call, and change the path to xd_receiver.htm too, and it should work okay.

In addition, double-check that the application's Connect URL (as set up via the Developer App in Facebook) points to a parent of the xd_receiver.htm file. So, if your app is hosted on http://www.mydomain.com, then looking at your code examples, your xd_receiver.htm will be at http://www.mydomain.com/xd_receiver.htm, and you'll want to have http://www.mydomain.com as the Connect URL.

If this still doesn't work, try installing Firebug (or similar tool) to have a look at the net traffic. When I was getting this to work, the Facebook Javascript API would fail silently, and it was only by inspecting the requests going back-and-forth that I spotted that Facebook didn't like my Connect URL.

In order to test that it's all working, I'd be tempted to use

FB.Connect.streamPublish();

rather that the line you posted, as it should pop-up a dialog, and is clearly given as a working example. I'm not sure what will happen if you just pass an empty string as an argument.

Finally, there are lots of IFrame-based Facebook apps out there - if you spot one that is doing something that you like, you can always have a look at their Javascript to find out how they achieved it. Or in other words, Facebook is full of example IFrame app code.

香橙ぽ 2024-08-24 20:48:51

您必须设置连接 URL 才能使用 javascript 库。尝试将您的书签网址设置为 http://apps.facebook.com/yourapp 看看是否有帮助。

You have to set your connect url in order to use the javascript libraries. Try setting your bookmark URL to http://apps.facebook.com/yourapp and see if that helps.

王权女流氓 2024-08-24 20:48:51

@Cyphus

是的,当我说“转到应用程序”时,我的意思是转到 Facebook 上的应用程序页面 (apps.facebook.com/myapp)。目前,我仅将回调 URL 设置为画布。一旦我尝试对画布和连接 URL 使用回调 URL,每当我尝试访问应用程序时,我都会被重定向到实际的回调 URL 本身,而不是加载到 facebook 内的 iframe 中。我不会直接从我的服务器请求它,因为这在某种程度上违背了拥有 Facebook 应用程序的目的。

@Cyphus

Yes, when I say 'going to the app' I mean going to the app's page on facebook (apps.facebook.com/myapp). Currently, I have my callback URL set to the canvas only. As soon as I tried using my callback URL for both the canvas AND the Connect URL, any time I tried to go to the app, instead of loading in an iframe within facebook, I was redirected to the actual callback URL itself. I don't request it directly from my server, since that somewhat defeats the purpose of having a facebook app.

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