Archive for the 'Facebook' Category

Facebook Connect Logout not working (Wordpress FBConnect plugin)

If you are having troubles with the Logout function of Facebook Connect using the wp-fbconnect plugin for Wordpress. Head into the wp-fbconnect plugin folder, open up fbconnect.js and modify the following code (add the code in red):

logout : function() {
FB.ensureInit(function() {
FB.Connect.logout();
setTimeout(function () {
window.location = FBConnect.home_url;
}, 3000);

});
},

I have tried a couple of numbers for the delay and 3 secs seems to be rather reliable for now. You might find other numbers more suitable for yourself. I have no explanation for this behavior currently. A wild guess might be when the logout is called, there is a delay between the data being updated and synchronised across the Facebook servers, hence when the page refreshes too fast, the user is read as being still logged in and FB resets his status to being connected. If you know whats going on, please contact me via the comments below. Thanks and Cheers.

Spaces added into email subject

If you are experiencing an issue where spaces are added into your email subject especially for dynamically generated subjects, consider using base64 encoding for your subject field in the email you send out or if you use non-latin characters or even binary data.

This problem occurs if you use xpertmailer for php which uses Quoted-printable encoding by default.

I quote one important information from the wikipedia page on Quoted-printable:

ASCII tab and space characters, decimal values 9 and 32, may be represented by themselves, except if these characters appear at the end of a line. If one of these characters appears at the end of a line it must be encoded as “=09″ (tab) or “=20″ (space).

If you are using xpertmailer, you can set the encoding in the following manner:

$m = new MAIL5();

$m->From(’you@example.com’);

$m->AddTo(’recipient@example.com’);

$m->Subject(’Look at this example, it is a very’ .
‘ long subject line which may be subjected to ‘ .
’spaces added unknowingly.’, ‘utf-8′, ‘base64′);

$m->Html = array(’content’ => ‘Your email HTML content here’);

echo $m->Send(’sendmail’) ? ‘Mail sent !’ : ‘Error !’;

De-mystifying Flash/Flex Facebook Applications Part 1

I wanted to write this post hopefully to help anyone develop flash applications that are running within Facebook’s canvas. There are currently 3 options in the AS3 Facebook API to hook up to facebook, namely startDesktopSession, startJSBridgeSession and startWidgetSession. Let me briefly talk about these 3 different ways of connecting and which one you should use to work with the facebook API.

startDesktopSession()

This method of connecting to the Facebook AS3 API is mainly for flash/flex applications running in webpages that have no relation with the facebook canvas. This applies to AIR applications as well.

When you use startDesktopSession, you generally have to supply your API_KEY and SECRET_KEY and navigate the user to facebook’s login page.

After that is done, you have to validate the desktop session after which you will receive an session_key that is limited or infinite depending on whether the user chose to save the login information.

Thereafter the API is ready for calls.

startJSBridgeSession()

This method of connecting to Facebook makes use of the facebook javascript API to make the calls and proxy the results back into the SWF using externalInterface calls.

You can see the javascript API on facebook at http://wiki.developers.facebook.com/index.php/JavaScript_Client_Library which has a pretty good example on hooking up the javascript API. (not a SWF example though)

The startJSBridgeSession simply makes similar calls using ExternalInterface from within flash and then gets the results back through a javascript callback.

Personally i haven’t had found any use for this yet.

startWidgetSession()

Use this if you are trying to make API calls from a flash app that is nested within an fb:iframe or fb:swf. You basically have to pass in your stage.loaderInfo.parameters which contains all the information the API requires to create a signature so that it can make proper API calls to facebook.

The API says this is depreciated but until there is a better way of calling APIs within flash (like facebook taking away allowScriptAccess, though highly unlikely), I would recommend this way of calling the API.

Important Note when using the 3 different methods

For those who are lazy to peek into the code within the API, for startDesktopSession(), asynchronous calls are made so it doesn’t matter if you add an eventListener before or after the startDesktopSession() to capture the results from facebook. However, for startWidgetSession() and startJSBridgeSession(), they are synchronous calls (meaning code executes line after line and the next line will not execute until the previous has finished executing) and you must add your eventListener before those functions or else the event handler will not fire. To be safe, add all your eventListeners before the call to start a session.

e.g.

var fb:Facebook = new Facebook();
fb.addEventListener(”complete”, fbCallback);
fb.startDesktopSession( ….. ) //can be startWidgetSession() or startJSBridgeSession()

Extra Misc Notes

If you are using custom headers with URLRequest for crossdomain calls, remember that for your crossdomain.xml, you must explicitly allow custom http headers within the crossdomain.xml. Adobe has a very comprehensive white paper for Flash Player security and its really worth a read.

You can find it at: http://www.adobe.com/devnet/flashplayer/articles/flash_player_9_security.pdf

An example of a crossdomain.xml that allows custom headers:

<?xml version="1.0"?>
<cross-domain-policy>

<!– Establish a meta-policy –>
<site-control permitted-cross-domain-policies=”master-only”/>

<allow-http-request-headers-from domain=”*” headers=”*”/>

<!– Data loading permissions are separate, and don’t affect headers –>
<allow-access-from domain=”*” />

</cross-domain-policy>

*Important for Flash CS3 users* If you are using the latest release from the google code SVN as of May 23rd 2008, search through the AS files in the pbking package and comment out import mx.controls.Alert, that code is meant for flex users.

Hope that this article will help anyone developing facebook applications with Flash/Flex/AIR.

For examples and code, there is a facebook authentication article on google code that gives the specifics of these 3 modes of authentication:

http://code.google.com/p/facebook-actionscript-api/wiki/FacebookAuthentication

I will post my own examples in the next few days, so watch this space ;)

Cheers!

FUG Facebook Presentation and Flash Player 10 availability on Adobe Labs!

The presentation yesterday was wonderful, thanks to FUG for the invitation to speak on facebook applications. It was great to catch up with some of the guys in the UG especially Ryan whom I have not met for quite some time. Ryan runs flashmove.com and they have a pretty awesome community there in the forums.

My slides and a recording of the presentation are available on fug.sg and the Memory Leak/GC demo is available at http://alvinzhang.com/gctest/index.html

I have made the source available on that page as well. Also took some time to file the online bug report to Adobe, hopefully they can resolve it asap, especially when we have first glimpses of flash player 10.

Flash Player 10
The new flash player 10 is off the hook. Im very impressed with its new features like the support for hydra filters (custom filters) and 3D support coupled with hardware support for rendering graphics, so for guys who have that ever powerful Geforce 9800 in your system, it can finally work its engines on this new version of flash player.

Unfortunately, some quick tests reveals that the new flash player 10 suffers from the same memory leak that flash player 9 suffers from (that is demonstrated in the GC demo above, you can test it against FP10 as well). Hopefully the guys over at Adobe fix this ASAP in time for the release of the flash player 10.

I have not tested the connection bug where downloads persist after the unload of a loader object. Will do it when I have the time.

Lastly those cool demos on http://labs.adobe.com/technologies/flashplayer10/demos are crippled by the inability to download the sources :( Please fix this please!

You can get Flash player 10 at Adobe labs: http://labs.adobe.com/technologies/flashplayer10/

Exciting times lie ahead for the RIA scene.

Facebook + Flash on May FUG

This is cool! I will be speaking about using Facebook with Flash CS3 this coming FUG session for May :)

Seems that the usergroup now has live video streaming so I guess its gonna be exciting, gotta do up my slides a little more proper then!

If you are residing in Singapore, or visiting Singapore any time, try to catch us at our monthly usergroup sessions where we share ideas and talk about everything flash/flex!

Singapore Flex Usergroup: http://fug.sg

Cheers!

Support the Turbanizer!

Had just done up the beta for Turbanizer.com :D It is an application that allows you to turbanize your friends. Theres a range of turbans to choose from and you can grab photos from Facebook or Flickr :)   Do let me know what do you all think after using it!

Turbanize your friends here!

Note when using startJSBridgeSession in Facebook AS3 API

Just decided to jot this down in case I forget in the future. Might be useful for those developing with the facebook as3 API too. When you are using the JSBridgeSession, it is important to add the event listener for Event.COMPLETE before starting the session, otherwise your callback function in the event listener will not fire.

Bug in JSON

Was working on the facebook API earlier and ran into a wierd problem where the JSON decoding was causing some conversions to go awry for reasons I didnt have the time to investigate. But basically it was causing very large numbers to get round off towards the last few digits. Went to the SVN and grabbed the latest copies from the repository and its working now. So all those who downloaded the default copy on google codes might want to update your JSON libraries if you encounter a similar problem.

Link to online browser of repository:
http://code.google.com/p/facebook-actionscript-api/source/browse