Skip to main content
Inspiring
October 6, 2011
Question

Facebook connection using Flash IDE

  • October 6, 2011
  • 1 reply
  • 670 views

Hi,

Ok so for many months now I have still been trying to find a decent tutorial on how to make a connection with Facebook using AS3 and the Flash IDE.

I must of tried over 50 tuts by now and none seem to work. Obviously the update of the API causes issues however I've yet to find one tutorial which actually works and can bring in profile info like name, friends list and profile pics.

Does anyone know of any tutorials showing this and how to achieve it?

p.s please don't point me to the Adobe docs or Flash API wiki as their information and documentation is out dated. I have gone through all their examples with no success.

I can only find examples for Flash Builder and maybe Flex, but I work with Flash IDE (5.5).

What I want to do is to be able to connect to FB through Adobe AIR on my iPhone. I'm pretty skilled in as3.0 and adobe air for mobile and have done several games, I just don't know how this FB works and no tutorial seems to work anymore etc.

Please, if you know how this works, can you please tell me?

Much much appreciated

This topic has been closed for replies.

1 reply

October 12, 2011

I can help better if you can write the steps you followed and the places where you got stucks or errors that you see.

Here are the general steps that you need to perform.

1. Add reference to the facebook API SWC library in your project.

2. call FacebookMobile.init(APP_ID,callback);

3. In callback of init the signature is of this form private function callback(session:Object, fail:Object):void . If you get a non-null session it is of type FacebookSession and you need to check if you already have a valid acces token. to do this check if you have a valid (non-empty non-null accessToken) and expiryDate is still not elapsed. Otherwise you will need to call login method.

4. If you do not have a valid accessToken you should call FacebookMobile.login. Which will ask the end user for credentials and athunticate the user. an example call I have used is as follows

                var swv:StageWebView = new StageWebView();

                app.stage.addEventListener(Event.RESIZE,function(e:Event):void{swv.viewPort = new Rectangle(0,0,app.stage.stageWidth,app.stage.stageHeight);});   

                FacebookMobile.login(handleLogin,app.stage,['user_photos','friends_photos','user_photo_video_tags','friends_photo_video_tags'],swv);

5. in handleLogin (Signature is same as that of init callback) if session still happens to be null the login attempt is failed and you can start inspecting the fail object for reason.

6. If you get a valid session. You are all set to call the API and get the data that you want for eg. you can use something like following to get all information about the logged in user.

            var p:Object = new Object();

            p.limit = 0;

            FacebookMobile.api("/me",function(result:Object, fail:Object):void{

                if(null == fail){

                    // process result for eg. result.name, result.username, result.gender, result.first_name

                }else{

                    ......

                }

            },p);

For the different api calls (The way I have used "/me" you can visit Graph API explorer)

Please revert back for any issues that you find.

I am working on a tutorial that allows one to use the Facebook Single Sign-On Feature in order to authenticate and authorize. Read more about it here. I will release the tutorial ASAP on my blog.