Question

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?

Was it helpful?

Solution

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.

Facebook.addJSEventListener("auth.sessionChange", onSessionChange);
Facebook.init(_appID, onInitFacebookConnect, 
      {cookie: true, 
       appId: _appID, 
       perms: "user_birthday,read_stream,publish_stream"});

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/

OTHER TIPS

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:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>

Replace

embedSWF("MyApp.swf", "flashContent", "640", "480", "9.0", null, null, null, {name:"flashContent"});    

with

swfobject.embedSWF("MyApp.swf", "flashContent", "640", "480", "9.0", null, null, null, {name:"flashContent"});  

i.e. swfobject. embedSwf

Worked like a charm!

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 ......

It seems that FBAS.getSwf() is using the name of the swf in its call to document.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.


var appId = "1234567890";

var swfNameAndId = "app_" + appId;

swfobject.embedSWF("/swfs/TestApp.swf", "app_placeholder", 760, 450, "9.0.0", false, { "appId": appId }, { "allowscriptaccess": "always" }, { "name": swfNameAndId, "id": swfNameAndId });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top