为什么 Facebook Actionscript API init() 不起作用?
我正在打电话 com.facebook.graph.Facebook.init(APP_ID, loginHandler);
使用actionscript api登录facebook(如本教程中所述:http:// /www.adobe.com/devnet/facebook/articles/flex_fbgraph_pt4.html)。但是,它似乎没有做任何事情。
查看 API 源代码,对 JS 进行的唯一调用是 ExternalInterface.call('FBAS.init', JSON.encode(options));
所需的两个 javascript 库是:
http://connect.facebook.net/en_US/all.js
FBJSBridge.js
但是,我在这些库中找不到任何对 FBAS 的引用。我是否使用了正确的库?我是否还错过了 FBAS 不存在的另一个原因?甚至为什么调用 Facebook.init() 没有任何作用?
I am calling
com.facebook.graph.Facebook.init(APP_ID, loginHandler);
to log in to facebook using the actionscript api (as explained in this tutorial: http://www.adobe.com/devnet/facebook/articles/flex_fbgraph_pt4.html). But, it does not seem to do anything.
Looking at the API source, the only call that is made to JS is
ExternalInterface.call('FBAS.init', JSON.encode(options));
The two javascript libraries which are required are:
http://connect.facebook.net/en_US/all.js
FBJSBridge.js
However, i cannot find any reference to FBAS in these libraries. Am I even using the correct libraries? Is there another reason I have missed as to why FBAS doesnt exist? or even why calling Facebook.init() does nothing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
FBJSBridge.js 已嵌入 SDK 中。查看 com.facebook.graph.core.FacebookJSBridge.as,您会发现 FBJSBridge.js 的整个 javascript 块都被添加到 com.facebook.graph.Facebook.as 构造函数中的ExternalInterface 上。
我一整天都在为此苦苦挣扎。我一直在观察 Facebook.init() 生成的 http GET,看起来它只是等到超时,此时生成了另一个 GET。它永远不会恢复正常。我尝试了其中的 APPID、APIKEY 以及各种参数组合,但我从未看到它回来。我必须得出结论,这就是它的工作原理。如果没有,那就是它的工作原理。 :-/
无论如何,您将在 FacebookJSBridge 的 JS 块中看到 FBAS 内部。因为 init 订阅了触发 Facebook.handleSessionChange() 的“auth.sessionChange”事件。您可以看到这就是您的回调被调用的地方。诀窍在于,每当 sessionChanges 时都会调用它。因此,即使下次该事件触发不是因为 FB.init() 的响应,您的回调仍然会在此时被调用。
如果您在调用 Facebook.init() 之前为“auth.sessionChange”设置自己的处理程序,并将“cookie”设置为 true,那么在创建 cookie 后,您将在调用 init 后立即触发 sessionChange 事件。 Init 的回调仍然没有被调用,因为 GET 永远不会得到响应。
您在该教程中找到的示例可能有效,但并不是您在实际组合应用程序时想要使用的示例。否则你总是会点击一个按钮来触发 fbconnect。看起来 oauth2 将是获得所需行为的方法,不需要每次都单击按钮来“连接”。您可以从 oauth2 获取会话密钥,然后使用 Flash/Facebook GRAPHSDK 或 JS,具体取决于您想要执行的操作最方便的一个。
这可能有帮助:
http://blog.yoz。 sk/2010/05/facebook-graph-api-and-oauth-2-and-flash/
FBJSBridge.js has been embedded in the SDK. Look at com.facebook.graph.core.FacebookJSBridge.as, and you'll see that the entire block of javascript that was FBJSBridge.js is tacked onto the ExternalInterface in com.facebook.graph.Facebook.as 's constructor.
I have been struggling with this all day. I have been watching the http GET spawned by Facebook.init(), and it looks like it just waits until it times out, at which point another GET is spawned. It never comes back normally. I tried the APPID, the APIKEY in there and all sort of combinations of parameters, but I never saw it come back. I have to conclude that's how its meant to work. If not, then that's how it does work. :-/
Anyway, you'll see inside FBAS in that JS block in FacebookJSBridge.as that init subscribes to the "auth.sessionChange" event which triggers Facebook.handleSessionChange(). You can see that is where your callback is called. The trick is that that is what gets called anytime the sessionChanges. So even if the next time that event fires isn't because of a response from FB.init(), your callback will still get called at that point.
If you set your own handler for "auth.sessionChange" before you call Facebook.init(), and you set "cookie" to true then after a cookie has been created you'll get a sessionChange event firing right after you call init. Init's callback still doesn't get called though because the GET never gets a RESPONSE.
The examples that you'll find in that tutorial may work, but are not what you'll want to use when actually putting an app together. Otherwise you are always going to click a button to trigger fbconnect. It looks like oauth2 will be the way to get the desired behavior of not needing to click on a button each time to "connect". You can get the sessionkey from oauth2 and then use the Flash/Facebook GRAPHSDK or JS depending on whichever is most convenient for what you are trying to do.
This might help:
http://blog.yoz.sk/2010/05/facebook-graph-api-and-oauth-2-and-flash/
失败的原因似乎有多种。请参阅以下链接:
http://code.google.com /p/facebook-actionscript-api/issues/detail?id=165
http://www.pastrytech.com/willy/FacebookActionScript3SDKExample.html" rel="nofollow">http:// /www.pastrytech.com/willy/FacebookActionScript3SDKExample.html
对我来说,Adobe 教程提供的包装文件中的脚本标签顺序是错误的。
确保在 swfobject 之前添加 Facebook JS 库。即确保您的脚本标签按以下顺序排列:
There seem to be multiple reasons why this fails. See these links:
http://code.google.com/p/facebook-actionscript-api/issues/detail?id=165
http://www.pastrytech.com/willy/FacebookActionScript3SDKExample.html
For me it was that the order of the script tags is wrong in the wrapper file that the Adobe tutorial provides.
Ensure that the Facebook JS library is added BEFORE swfobject. I.e. ensure your script tags are in this order:
替换
为
swfobject。 embedSwf
效果非常好!
Replace
with
i.e. swfobject. embedSwf
Worked like a charm!
这里是对你的问题的回答。
http://novacoders.blogspot.com/2011/04 /facebook-graph-api-init-problems.html
Here is answer on your questions.
http://novacoders.blogspot.com/2011/04/facebook-graph-api-init-problems.html
就我而言,是index.template.html 不起作用。我需要:
1)FB JS SDK的参考
2)使用fb-root div作为解决我的问题的body标签内的第一个条目
。
编辑:我很困惑 Facebook.init() 仅在用户登录时才起作用。为了进行身份验证,我调用 Facebook.login
Edit2:重新访问了这个东西...这次我错过了画布 url 需要指向您的页面,如果不是,当然调用会转到另一个页面,并且您永远不会收到响应。很明显,但它再次击中了我......
In my case it was the index.template.html that did not work. I needed:
1) a reference to the FB JS SDK
2) use fb-root div as first entry inside the body tag
that solved my issue.
Edit: I was confused that Facebook.init() only works when a user is logged in. For authentication I call Facebook.login
Edit2: Revisited this thing... This time I missed that the canvas url needs to point back to your page, if not of course the call goes to another page and you never receive a response. Obvious, but it hit me again ......
看来
FBAS.getSwf()
在调用document.getElementById
时使用了 swf 的名称。因此,如果您指定 id 但未指定名称,则 FacebookJSBridge.as 的 javascript 会查找 id 为 null 的元素。
或者,如果您指定名称但未指定 id,则 FacebookJSBridge.as 的 javascript 会查找适当的字符串,但存在没有此类 id 的元素。
如果您指定名称和相同的 id,那么它实际上可以找到 swf。
It seems that
FBAS.getSwf()
is using the name of the swf in its call todocument.getElementById
.So, if you specify an id but not a name, then FacebookJSBridge.as's javascript looks for an element with the id of null.
Or, if you specify a name but not an id, then FacebookJSBridge.as's javascript looks for the appropriate string, but an element with no such id exists.
If you specify a name AND an identical id, then it can actually find the swf.