Author Archive
If your Flash AS3 Facebook API is not working, check these things…
If you are having problems with the Facebook AS3 API, note that there are not only Flash set up requirements but HTML requirements as well. I was having sporadic issues – I could log via Facebook.login() but my callback function would not fire from Facebook.init().
First, make sure the following is in your <head> tags:
<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>
Next, make sure that you have this below your opening <body> tag:
<div id="fb-root"></div>
And that should do it!
(advice taken from http://code.google.com/p/facebook-actionscript-api/issues/detail?id=395)
Facebook API – getSession() returns NULL due to Oct. 2011 OAuth switch
I was building a new site using my Facebook framework from last year, and suddenly everything no longer worked! After digging around with great frustration I found some documentation from Facebook discussing the issue. Due to the recent OAuth 2.0 requirement, certain methods (such as getSession() ) are now deprecated. In this case, I will now have to use authResponse() calls and FacebookAuthResponse objects instead of FacebookSession objects.
You can read more at the official Facebook post below.
Flash Builder 4.6 not compatible with Facebook API (1.8.1)
Since upgrading to Flex 4.6 and Flash Player 11, Flash Builder 4.6 has broken the Facebook API because of its new, native JSON class.
This leaves you a couple of options.
1. Wait for Facebook and publish to 10.3.183
2. Tweak Facebook’s API to use the native class
3. Rename the as3corelib JSON class and continue using it.
I chose option 3 because Facebook used some of the error-catching mechanisms from as3corelib’s JSON classes and I didn’t want to break anything. Also, considering that Facebook is the subject in question, I want to do as little as possible to it because it already breaks on its own.
Note that Flash Builder will not let you refactor com.adobe.serialization.json.JSON because it’s not smart enough to tell it and the default class apart. So you’ll probably want to use the project search and replace feature. I renamed my class to JSONCore.
Facebook AS3 API – Not getting response from auth.sessionChange or auth.login after password login?
Facebook’s AS3 API has handy built in methods for dealing with Javascript / Flash communication regarding authentication and other Facebook events. However, it doesn’t always work when it should. Consider the situation below:
Facebook.addJSEventListener('auth.login', onSessionChange);
var opts:Object = {scope:"publish_stream, user_photos, create_event"};
Facebook.login(onResult, opts);
In this case, we simply want to login and get the response from Facebook when our user has completed authentication.
This works when the user is already logged into Facebook and Flash merely needs to register the application instance. However, if the user has to deal with the login prompt, the API does something funny. Flash will receive the response from Facebook but it will not necessarily be ready on Facebook’s server by the time you get it. Meaning your method receiving your auth.login event will be called but if you try to do anything like …
Facebook.api('/me',onMeResult);
… your result will be an unauthenticated user error.
So the problem is that Facebook doesn’t assure it’s ready on its end before it sends you the response. My solution is terrible but it works — consider using a timer for your first API call with one second intervals from your auth.login method. In case the user cannot log in you might want to limit it to 5 cycles since no one will realistically time out longer than 5 seconds.
Flash: Timeline dynamic TextFields losing formatting with new content?
You may notice that dynamic TextFields originating from the timeline occasionally maintain their formatting and sometimes lose it, even with programmatic fixes. This is because the problem lies in two different places, and this is how to fix it.
First, it is important to know that Flash will reset the formatting for any new text to that TextField’s defaultTextFormat. If you do not set this property you will have to setTextFormat after every time you change the text. Otherwise you will be stuck with defaults that you probably didn’t want.
Most problems will be solved with this code (and it’s what most people searching Google are probably looking for). I made this static utility method to do all of my timeline TextField formatting to save time and clutter.
public static function formatTextfield(textField:TextField, label:String, html:Boolean = false, align:String = "left"):void {
var fmt:TextFormat = textField.getTextFormat(); textField.defaultTextFormat = fmt; textField.autoSize = align;
if(html){ textField.htmlText = label; } else { textField.text = label; }
}
Here’s the rundown. Collect the TextFormat data before you change anything. Then you set the default to the existing format to take care of any future changes. Then do your text. The end.
Now this will fix most people’s problems. However, there is another behavior in Flash that you need to be aware of. If there is text with more than one type of formatting in the TextField, Flash will revert to its defaults (which will lose all of your kerning, for example). Also, if there is no text in the field, it will also revert to defaults. I like putting a simple space in my TextFields to keep them looking clean, but as long as you keep it simple (one character is safest), you should be in good shape.
Note that if you are someone who is doing runtime font loading, you do not want to be putting any text from your primary font on the timeline or things can get all sorts of wonky. In this case you’d probably want to do your formatting then switch to a default font and reset the font programmatically.
Facebook Javascript Update / OAuth 2.0 Requirement breaking login pop-up?
In their December 2011 changes to the Javascript SDK, Facebook has caused certain websites using the AS3 API to break. The issue arises with the login pop-up window no longer appearing when Facebook.login is called.
The problem lies within the perms parameter used in Facebook.login. You must now use scope instead.
var opts:Object = {scope:"publish_stream, user_photos, create_event"};
Facebook.login(onResult, opts);
This solve was found at the facebook-actionscript-api Google Code group. Thanks guys!
How to send URL Variables into a Facebook App / Tab
If you need to send URL variables into a Facebook App (within a Page tab), doing so is surprisingly easy.
Firstly, know that the JSON-based object you are interacting with is called signed_request. It is used primarily for internal communication between Facebook and your app. However, Facebook does give you one app_data variable to use for your own variables. To send a variable to your Facebook app, all you need to do is set a value to app_data in your URL request and Facebook will handle communicating that data to your app’s iFrame.
URL example (sending data):
https://www.facebook.com/pages/Walrus-In-A-Canoe/?sk=app_0000000000&app_data=APP_DATA_CONTENT
For an example of retrieving your app_data, I have found some nifty code from fbadurbin on this thread which I have pasted below.
$signed_request = $_REQUEST['signed_request']; // Get the POST signed_request variable.
if(isset($signed_request)) // Determine if signed_request is blank.
{
$pre = explode('.',$signed_request); // Get the part of the signed_request we need.
$json = base64_decode($pre['1']); // Base64 Decode signed_request making it JSON.
$obj = json_decode($json,true); // Split the JSON into arrays.
$page = $obj['page']; // Get the page array. It has a sub array.
echo("Your App Data: " . $obj['app_data']);
}
else
{
die('No signed request avaliable.'); //If there is no signed_request, stop processing script.
}
How to connect Facebook Apps to Facebook Pages with no View App Profile button
As of late 2011, Facebook has begun to phase out the View App Profile button you may have used to connect Facebook Apps to fan pages.
The replacement technique is rather strange. You need to type a specific URL into your browser and fill out the following:
https://www.facebook.com/dialog/pagetab?app_id=APP_ID&redirect_uri=TAB_SOURCE_URL
If you provide the correct parameters, you will receive the following dialogue box:
You can read more at Facebook’s official documentation below.
https://developers.facebook.com/docs/reference/dialogs/add_to_page/



