无法获得'edge.create'回调以与Facebook javascript SDK一起使用 [英] Can't get 'edge.create' callback to work with facebook javascript SDK

查看:109
本文介绍了无法获得'edge.create'回调以与Facebook javascript SDK一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Facebook javascript SDK的'edge.create'回调函数在用户单击页面上的赞"按钮时发送警报.最终,我的目标是在页面上重新生成样式,以便单击时可以动态调整Facebook小部件div的大小.即使对于警报,我也无法使回调工作.

I'm trying to use the 'edge.create' callback function of the Facebook javascript SDK to send an alert when a user clicks the like button on a page. Ultimately my goal is to have it regenerate styles on the page so that it can resize the facebook widget div dynamically when clicked. I cannot get the callback to work even for the alert though.

<html lang="en">
<head>
    <title></title>
    <script   src="http://connect.facebook.net/en_US/all.js#appId=216985861663967&amp;xfbml=1"></script>
    <script>
        FB.Event.subscribe('edge.create', function() {
            alert('Liked');
        });
    </script>
</head>
<body>
<div id="fb-root"></div>
<fb:like send="false" layout="button_count" show_faces="false" font=""></fb:like>

</body>
</html>

有什么想法为什么不起作用?单击该按钮时,将显示错误:

Any ideas why this isn't working? When the button is clicked it gives the error:

不安全的JavaScript尝试访问带有URL的框架

Unsafe JavaScript attempt to access frame with URL

后来说,域,协议和端口必须匹配.

and later says Domains, protocols and ports must match.

推荐答案

根据您的描述,我猜您是在本地服务器上的Chrome/Safari中进行测试的吗?

From your description I'm guessing you're testing in Chrome/Safari on a local server?

尝试将喜欢"按钮的URL设置为现有的网址:

Try setting your Like Button URL to an existing Web address:

<fb:like href="http://google.com" ...

重要的一点是,警报取决于Like的成功,这取决于Facebook可以访问的URL.您将无法喜欢仅在本地服务器上存在的URL(例如 http://localhost :3000/my-page.html ).显然,喜欢Google是一个测试修复程序;您可以将代码推送到登台服务器以达到相同的效果,但是这需要更多的时间和精力.

An important note is that the alert depends on the Like's success, which depends on the URL being reachable by Facebook. You won't be able to Like a URL that only exists on your local server (ex. http://localhost:3000/my-page.html). Obviously Liking Google is a test fix; you can instead push your code to a staging server for the same effect, but it takes more time and effort.

当我进行此更改时,赞"按钮和警报在Mac的Chrome 12中起作用,但仍然看到与您相同的错误.我认为Chrome只是对iframe敏感;我怀疑该错误是否可以避免.

When I make this change the Like Button and alert work in Chrome 12 for Mac, but I still see the same error as you. I think Chrome is just sensitive with iframes; I doubt the error can be avoided.

如果我进行了上述更改,则在Mac版Firefox 5中仍然无法使用.我从Facebook的all.js中收到错误e.root is undefined,并且赞"按钮甚至没有出现.

If I make the above change, it still doesn't work in Firefox 5 for Mac. I get the error e.root is undefined from Facebook's all.js and the Like Button doesn't even appear.

如果将all.jsFB.Event.subscribe()脚本移到fb-root div下方,则会显示赞"按钮,并且警报将正常运行.

If I move the all.js and FB.Event.subscribe() scripts below the fb-root div, the Like Button shows up and the alert works with no errors.

根据 Facebook的文档,您需要将Facebook的XML名称空间添加到标签以在Internet Explorer中呈现按钮:

According to Facebook's documentation you need to add Facebook's XML namespace to your <html> tag for the button to render in Internet Explorer:

<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">

这篇关于无法获得'edge.create'回调以与Facebook javascript SDK一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆