While The Facebook Graph API article becomes pretty popular and a lot of developers keep asking me to publish some practices I use, I managed to create this blog post. Here is a list o some functions you may want to extend FacebookOAuthGraph Class with.

Extending & Singletonize

First, lets make our class singleton, so the whole flash project can simply access and use one instance

133 comments so far

Hi Jozef,
Great class, thanks for this, we’ve been using PHP solution for FB apps, but I think we’ll start using your solution from now on!
Have one question though..
It’s about autoconnect function.. It has a event callback : “AUTHORIZED” when the user get’s successfully authorised. Is there a callback when autoconnect couln’t authorise the user ?
I’ve tried almost everything.. adding UNAUTHORIZED event to facebook instance, DATA event – none of the them get called on autoconnect fail..
Also tried adding listeners to URLLoader instance returned from facebook.autoconnect (DATA, COMPLETE) no luck..
Any idea how to solve this ?
Thanks.

Hi Slavo,
I like to hear that you like it. I hope we can fix the issues now…

there is an autoConnect() function that can take parameters (flashvars):
– if parameters contains session and access_token the lib tries to verifyToken()
– if it does not containt session lib uses token stored in sharedObject to verifyToken()

verifyToken() creates URLLoader contacting facebook to see if the token is valid:
– if the response is valid verifyTokenSuccess() is called dispatching AUTHORIZED on FacebookOAuthGraph instance
– if the response is not valid there is no handler for this by default. you can extend verifyToken() function to receive error events over URLLoader…

I am just reading that you are already able to handle events here (on autoConnect()), so what you have to do is, listen for HTTPStatusEvent and IOErrorEvent. I believe facebook responses with error when the authorization fail, that is why you failed with catching it like Event.COMPLETE

I have a problem using the method video.upload, that parameter should not go to [no name]- data – The file for the video data. This is a ByteArray? I hope you can help as facebook returns me this error “error_code”: 7, “error_msg”: “This method must-run on api-video.facebook.com. If possible an example on using this method would be helpful. Thank you for your attention.

In this case, that part is not using the method “video.upload” because in this way was like I got a facebook pictures and it works, I think the method used in this case is this http://developers. facebook.com / docs / reference / api / video, seeing the image works with this http://developers.facebook.com/docs/reference/api/photo honestly I feel very lost on this problem I hope suggestions.

I think here I come … This code is supposed to upload a video to Facebook,

//Call Video Graph API
public function uploadVideoCall(bytes:ByteArray, message:String):void
{
trace(“Video UPLOADER”);
var mpLoader:MultipartURLLoader = new MultipartURLLoader();
mpLoader.addEventListener(Event.COMPLETE,onMultiPartVideoLoader,false,0,true);
mpLoader.addEventListener(IOErrorEvent.IO_ERROR,onMultiPartVideoLoader,false,0,true);
mpLoader.addEventListener(ProgressEvent.PROGRESS,onMultiPartVideoLoaderProgress,false,0,true);
mpLoader.addVariable(“message”, message);
mpLoader.addFile(bytes, “Video.flv”, “Test Video”);
super.loaderAddListeners(mpLoader.loader);
mpLoader.load(apiSecuredPath + “/me/videos?access_token=”+ _token);
}
private function onMultiPartVideoLoader(e:Event):void{
trace(“Sucefull Upload: “+e.currentTarget);
}
private function onMultiPartVideoLoaderError(e:IOErrorEvent):void{
trace(“IO ERROR: “+e.currentTarget);
}
private function onMultiPartVideoLoaderProgress(event:ProgressEvent):void{
trace(“\n” + event.bytesLoaded + ” bytes de ” + event.bytesTotal + ” bytes subidos.”);
}
///////////////////////////////////////////////////////////////////////
the problem is that I receive Uploaded response, but does not really. I think the problem is due to deliver a missing parameter type, but honestly not which is (I tried uploading a picture and works perfectly using this code and only changing mpLoader.load (apiSecuredPath “/ me / photos? access_token =” _token)) I have read and found that it is possible that this method or called in facebook is bad, I like me’d say if it’s true or not the video upload is still not well done on facebook. I await your response and I apologize for so much spam

MauroX, Garo hi guys
I really think you should use old rest api method for now for this. readhttp://developers.facebook.com/docs/reference/rest/video.upload
what you should do is to use the proper arguments with the request resulting in something like this:
mpLoader.load(“http://api-video.facebook.com/method/video.upload”);

I’m thinking about this method to post to wall and i was wondering: it’s only possible to post to the current user wall? Is not possible to post to his wall and to some page (for example the app profile page)?

The html page that wraps the swf is in domainA.com and declared in the facebook app, but the swf is in domainB.com (caching server, cdn with transparent redirection). When I try to connect to facebook, the auhorisation fails. Any idea?

P.S. When the html and the swf are in the same domain, everything worksfine…

@Ben,
I can see you defined .swf script access for crossdomain for both .swf files, as well as localconnection name with underscore correctly. Popup opens and closes by itself (however I am not able to find close command in javascript – maybe injected from callback.swf?) … I can also see the redirect from facebook tohttp://www.monstromatic.com/bin/callback.html#access_token=***********&expires_in=4560
so window.location.hash should contain correct info… I believe there is some issue with handling hash value in your flash. You should debug that

I’m confused about how to get access to the profile pic of the user tho – when i try the callComplete portion of the code – a status update gets posted but the result is event.rawdata is not recognized as a ByteArray – any idea what I might be doing wrong?

I could post on authenticated user’s friends wall successfully only when the pop-up window (normal callback.html) closed automatically. Firefox and crome browsers are able to close the callback.html after authentication, but Internet explorer unable to close the callback.html automatically.

please suggest !
I would also like to know the purpose of Advanced callback.html

Hi Gopi,
In order to make calls to api you need a token. When you authorize your app in popup, the token is pushed in the last step into callback.html. Now callback.html hast to push it back to your main app (via javascript-simple or LocalConnection-advanced callback). It it succeed with sending the token to the main app, it tries to close itself using javascript window.close() method. Could you somehow debug the issue with IE and send some report where the javascript fails?

Hi, Jozef..
Please, i used the photo uploading code through the graph API but i don’t know how i used it in my project..
can you send me the step by step code for this with file names in which i have to update the code..

hi Vaishali
have a look at “Uploading Photo” section. copy and paste the conde into your Facebook class (extends FacebookOAuthGraph). you may be missing MultipartURLLoader dependency, you can download it from internet. everything else should be selfexplanatory