Facebook Graph API & OAuth 2.0 & Flash (update)

As previously mentioned, facebook released a new Graph API. It is based on OAuth 2.0 protocol (old authorization token also works). While it is fresh thing, there is no much ActionScript stuff around, so I came with FacebookOAuthGraph class. This class is meant to be used as an abstract class, while it contains just the basic authentication algorithm and call method to request data. It stores access token in SharedObject, so next time you came into app, you get connected on background without noticing (no popup etc.). Your token should expire in 24 hours.

Here is the code for the following flex app, to make it work, get latest FacebookOAuthGraph and FacebookOAuthGraphEvent classes.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
    applicationComplete="init()">
<mx:Script>
<![CDATA[

    import sk.yoz.events.FacebookOAuthGraphEvent;
    import sk.yoz.net.FacebookOAuthGraph;

    // facebook Application ID
    private var clientId:String = "268718683475";

    // path to our callback
    private var redirectURI:String =
        "http://blog.yoz.sk/examples/FacebookOAuthGraph/callback.html";

    // required extended permissions
    private var scope:String = "publish_stream,user_photos,user_photo_video_tags";

    private var facebook:FacebookOAuthGraph = new FacebookOAuthGraph();

    [Bindable] private var connected:Boolean;

    private function init():void
    {
        facebook.clientId = clientId;
        facebook.redirectURI = redirectURI;
        facebook.scope = scope;
        facebook.useSecuredPath = true;
        facebook.addEventListener(FacebookOAuthGraphEvent.AUTHORIZED, authorized);

        // stage.root.loaderInfo.parameters
        facebook.autoConnect(parameters);

        log.text += "checkSavedToken()\n";
    }

    private function connect():void
    {
        facebook.connect();

        log.text += "connect()\n";
    }

    private function authorized(event:FacebookOAuthGraphEvent):void
    {
        connected = true;

        log.text += "authorized\n";
    }

    private function call(path:String, binary:Boolean):void
    {
        var loader:URLLoader = facebook.call(path);
        loader.dataFormat = binary
            ? URLLoaderDataFormat.BINARY
            : URLLoaderDataFormat.TEXT;
        loader.addEventListener(FacebookOAuthGraphEvent.DATA, callComplete);
        log.text += "call(" + path + ")\n";
    }

    private function changeStatus(message:String):void
    {
        var data:URLVariables = new URLVariables();
        data.message = message;
        var method:String = URLRequestMethod.POST;
        var loader:URLLoader = facebook.call("me/feed", data, method);
        loader.addEventListener(FacebookOAuthGraphEvent.DATA, callComplete);
        log.text += "changeStatus(" + message + ")\n";
    }

    private function callComplete(event:FacebookOAuthGraphEvent):void
    {
        log.text += "call completed -> see result\n";

        if(event.rawData is ByteArray)
        {
            var loader:Loader = new Loader();
            loader.loadBytes(event.rawData as ByteArray);
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
                function():void
                {
                    image.source = loader;
                });
        }
        else
        {
            result.text = event.rawData.toString();
        }
    }
]]>
</mx:Script>
<mx:HBox>
    <mx:Button click="connect()" label="connect" />
    <mx:Text text="{connected ? 'connected' : 'not connected'}" />
</mx:HBox>
<mx:HBox visible="{!connected}" includeInLayout="{!connected}">
    <mx:Text text="#access_token=121161974560905%7C2..." />
    <mx:TextInput id="hash" />
    <mx:Button label="add hash" click="facebook.confirmConnection(hash.text)"/>
</mx:HBox>
<mx:HBox>
    <mx:TextInput id="path" text="me" />
    <mx:Button label="call" click="call(path.text, false)" enabled="{connected}"/>
    <mx:Spacer width="20" />
    <mx:TextInput id="path2" text="me/picture" />
    <mx:Button label="call binary" click="call(path2.text, true)" enabled="{connected}"/>
</mx:HBox>
<mx:HBox>
    <mx:TextInput id="status" text="testing FacebookOAuthGraph" />
    <mx:Button label="change status" click="changeStatus(status.text)" enabled="{connected}"/>
</mx:HBox>
<mx:HDividedBox width="100%" height="100%">
    <mx:TextArea width="30%" height="100%" id="log"/>
    <mx:TextArea width="70%" height="100%" id="result"/>
    <mx:Image id="image" />
</mx:HDividedBox>
</mx:Application>

Make sure your html wrapper defines correct allowScriptAccess and both id and name for <object> tag. This enables ExternalInterface.objectID. With swfobject use:

var params = {
    allowScriptAccess: "sameDomain"
};

var attributes = {
    id: "FacebookOAuthGraphTest",
    name: "FacebookOAuthGraphTest"
};
swfobject.embedSWF("FacebookOAuthGraphTest.swf", "alternative", "100%", "100%", "10.0.0",
    "expressInstall.swf", flashvars, params, attributes);

callback.html pushes url hash into flash app. When running this application from desktop (creating/debugging), your callback.html located on public domain has no access to its opener (different domain – XSS), so you need to pass access_token manualy into <TextInput id=”hash”>, but once your flash application is on the same domain with callback, it works automaticaly.

callback.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="sk" lang="sk" dir="ltr">
<head>
	<script type="text/javascript">
	<!--
		if(window.opener && window.opener.confirmFacebookConnection)
		{
			window.opener.confirmFacebookConnection(window.location.hash);
			self.close();
		}
	//-->
	</script>
</head>
<body>
<p>You may now close this window.</p>
</body>
</html>

Click connect and allow facebook application. Facebook redirects to callback.html that pastes hash into flash and closes popup. Now you are authenticated. Next time you visit this flash application (refresh this page) you will get authenticated in background (if your access token is still valid). Notice, some graph api calls returns JSON objects (me), other may return binary data (me/picture). For now it may take some time to finish calls (5 second or more), but I hope facebook will soon make it fast.

You get your JSON decoded data via event.data. Just make sure you do not try to decode ByteArray (eg. me/picture)

// call("me")
private function callComplete(event:FacebookOAuthGraphEvent):void
{
    trace(event.data.name);
}

Some calls to test:

Friends:             me/friends
News feed:           me/home
Profile feed (Wall): me/feed
Likes:               me/likes
Movies:              me/movies
Books:               me/books
Notes:               me/notes
Photos:              me/photos
Videos:              me/videos
Events:              me/events
Groups:              me/groups

Additional information about my facebook app (see all settings):

Application ID:    268718683475
Connect URL:       http://blog.yoz.sk/examples/FacebookOAuthGraph/
Base Domain:       yoz.sk
FBML/iframe:       iframe
Developer Mode:    Off
Application Type:  Desktop
Private Install:   No

Based on facebook access token, it should be valid approximately for 24 hours. Notice the bold part, works as expiration time (unix time format). Use FacebookOAuthGraph.tokenToExpiration() to parse Date:

access_token=268718683475%7C2.w3fjqz80Xi1CdBXt7Ygh6A__.86400.1273158000-1215645368%7CDGv2l2HtTymd6cM6Fy_8k6P_8CQ.

Important update: May 19, 2010: Application is working again. Due to massive support in bug tracker (thanks all for your votes), facebook devs changed secured crossdomain.xml, so it allows unsecured requests. changeStatus() method added into example and some minor changes in FacebookOAuthGraph class (please update).

Here is what happend and why this app was not working for a while:

  • May 11, 2010: facebook changed rules, so requests on unsecured graph service (via http://graph.facebook.com…) were limited to just those without access_token parameter. Requets to secured service (https://graph.facebook.com) resulted in security violation due to missing secure=”false” parameter in crossdomain.xml
  • May 12, 2010: bug submitted
  • May 12, 2010 – May 14, 2010: massive bug voting
  • May 14, 2010: Bug confirmed by facebook dev team
  • May 19, 2010: Bug fixed, crossdomain file changed

I am glad that facebook devs listens and care. :-)

FAQ

How can I use this class in my iframe canvas page?

Please read article Authorizing Iframe Facebook Applications For Graph API

How can I make this class do more advanced things and what are the best practices?

Please read article Extending FacebookOAuthGraph Class, where all the most comon extendings are described.

When I connect with this app in one browser (firefox), and I run another browser (chrome) I get automatically connected. Why?

Your authorization token is stored in SharedObject, that is OS-user persistent (eg. windows user). No matter what browser you run, all of those reads data from one SharedObject. If you need cookie or session persistent authorization, please extend my class and override methods that use SharedObject.

How to add request parameters into my call?

Pass URLVariables object as a second parameter to call() method:

// eg. in order to make this call "me/picture?type=large", do the following:
var data:URLVariables = new URLVariables();
data.type = "large"
call("me/picture", data);

Why I can not access me/photos?

Facebook has changed rules again. You also need “user_photo_video_tags” permission within your app. I have already added it into my app, so please remove your browser cache, refresh and click connect button again (even if you are connected already). Now it should work.

How to upload photo with graph api?

This is a piece of working code from Sean, thnx Sean:

// MultipartURLLoader by Eugene Zatepyakin can be found here: http://bit.ly/9wx4q7
public function uploadImageCall(path:String, ba:ByteArray, message:String, token:String=null):MultipartURLLoader
{
    var mpLoader:MultipartURLLoader = new MultipartURLLoader();
    mpLoader.addVariable("message", message);
    mpLoader.addFile(ba, "image.jpg", "image");
    loaderAddListeners(mpLoader.loader);
    mpLoader.load(apiSecuredPath + "/me/photos?access_token="+ token);
    return mpLoader;
}

Can I make fql calls with this class?

However graph api does not implement fql calls, you can make fql calls using this class. The resulted data are not JSON but XML:

var data:URLVariables = new URLVariables();
data.query = "SELECT uid, name FROM user WHERE uid = XXX"; // insert your uid
var loader:URLLoader = facebook.call("method/fql.query", data,
    URLRequestMethod.POST, null, "https://api.facebook.com");
loader.addEventListener(FacebookOAuthGraphEvent.DATA, fqlComplete);

private function fqlComplete(event:FacebookOAuthGraphEvent):void{
        var xml:XML = new XML(event.rawData);

For fqlComplete method, please read Parsing FQL result article.

Can I post feeds with attachments?

Graph API has not documented attachment functionality for feeds, anyway, you can publish streams with attachments with this class as simple as:

var media:Object = {};
media.type = "flash";
media.swfsrc = "http://zombo.com/inrozxa.swf";
media.imgsrc = "http://blog.yoz.sk/wp-content/uploads/3d-150x150.jpg";
media.width = "80";
media.height = "80";
media.expanded_width = "120";
media.expanded_height = "120";

var attachment:Object = {};
attachment.name = "test name";
attachment.href = "http://blog.yoz.sk"
attachment.description = "test description";
attachment.caption = "test caption";
attachment.media = [media];

var data:URLVariables = new URLVariables();
data.message = "test message";
data.attachment = JSON.encode(attachment);

facebook.call("method/stream.publish", data, URLRequestMethod.POST, null, "https://api.facebook.com");

How can I develop my app locally when callback only works on the domain?

While callback is not able to push access_token into your app on runtime, I just copy access_token value into my code and publish again:

if(!parameters.session)
parameters.session = JSON.encode({
    access_token:String("123864964303507%7C2._pSS7WlemeGB9M0RV8Vnuw__.3600.1276246800-1215645368%7C-kYjWPx4MR6DXc5Clcnv5kXX3t4.")
        .replace(/\%7C/g, "|")
});
facebook.autoConnect(parameters);

Hi Is there a way to implement a “i Like” button with your class?

Sorry, you can not use graph API to like stuff, there is no method for that. Even by testing like request:

href: http://www.facebook.com/pages/***
node_type: page
edge_type: like
page_id: 12345
action_text
now_connected: true
nctr[_mod]: connect
post_form_id: 123ABF***********
fb_dtsg: TAfAJ
post_form_id_source: AsyncRequest

… post_form_id is some static required parameter that you can not guess.

This example app works with Internet Explorer, but my one results in Error #2032

Please complie your app to Flash Player 10 (or later). It should fix this issue. Credits goes to Garcimore :-) , thnx. The issue has been identified as header Content-Type: application/json, that is returned from facebook. Suggested workaround (by facebook dev team) is to use POST variables with your requests, however it is reported as not working solution.

253 comments so far

  1. [...] (May 5, 2010): I have created Facebook Graph API & OAuth 2.0 & Flash – FacebookOAuthGraph ActionScript 3 class to use with OAuth 2.0 and [...]

  2. Kevin Fox May 7, 2010 00:06

    When I tried the demo app on this page…

    Error #2044: Unhandled IOErrorEvent:. text=Error #2124: Loaded file is an unknown type.

    I got this when I tried a ‘me/feed’, ‘me/friends’ etc.

    Is this normal? Am I doing something wrong?

  3. Jozef Chúťka May 7, 2010 10:44

    Hi Kevin,

    it should work ok, I have just tested it on 2 accounts. It may be required to grant more extended permissions (via scope = “publish_stream,user_photos,…”), but in this case it should work without change. Interesting, every URLLoader from FacebookOAuthGraph.call() method handles its IOErrorEvent, so I guess the error message is not from this application, and it may have been caused by drawing application on the top of this blog.

    please try again and let me know

  4. Maz May 7, 2010 16:51

    hi,
    really thank you for the source!!
    but i got an issue that i can resolve:
    whan facebook call my callback.html (that is the same as your), i receive an error from firebug “flash.confirmFacebookConnection is not a function”. but “externalinterface.addcallback” is in your class…

    i use the same technique as your to embed flash in html. and i’ve added Security.allowDomain(“…mydomain…”); to ensure privacy policy…

    <!–
    NO FLASH PLUGIN

    <!–

    i don’t know…

  5. Maz May 7, 2010 16:55

    argh it didin’t wrote my embed code, but i don’t think is so useful

  6. Jozef Chúťka May 7, 2010 17:27

    Hi Maz,

    make sure you set both “id” and “name” for flash object in html, that enables your ExternalInterface access objectID.

    var attributes = {
    id: “FacebookOAuthGraphTest”,
    name: “FacebookOAuthGraphTest”
    };

    swfobject.embedSWF(“FacebookOAuthGraphTest.swf”, “alternative” , “100%”, “100%”, “10.0.0″,
    “expressInstall.swf”, flashvars, params, attributes);

  7. Maz May 7, 2010 17:47

    hi jozef!
    yes, i did it…

    “……..

    …….”

    testing on latest firefox on osx.
    however you’re test app doesen’t work on my safari and chrome! could be a popup blockin’ problem?

  8. Jozef Chúťka May 7, 2010 17:55

    yes it could be popup blocker, I am unable to handle blockers :( … thinking about something like:
    http://blog.yoz.sk/2010/01/elegant-facebook-login-for-desktop-application/

  9. Kevin Fox May 8, 2010 06:27

    Kevin here again…
    Thank you sooooooo much for making these classes available. I converted your Flex app into regular ol’ Flash and it worked without a hitch. The authentication is totally smooth and the code was concise and easy to understand. I was a little out of my depth there, trying to figure OAuth2.0 out myself, so you saved my ass. Big thanks!

  10. Jozef Chúťka May 8, 2010 09:45

    thanks Kevin, glad to hear that

  11. Maz May 8, 2010 12:32

    ok it works, thank you :)
    the problem was a strange bug between externalinterface.callback and firefox on mac!

    i resolved this bug making a callback to flash functions after a timetout!

    now i got a new question, do you ever tried to publish something to the feed of the user with your classFacebookOAuthGraph ? i’m triyng without results…

    thank you again !!

  12. gurpreet May 8, 2010 15:13

    I’m facing the same problem as Kevin. I’m able to connect but when I enter ‘me/photos’ I get the following error…

    Error #2044: Unhandled IOErrorEvent:. text=Error #2124: Loaded file is an unknown type.

    I want to display a list of logged in user’s albums and corresponding photos. Plz help how shall I go about it.

  13. Jozef Chúťka May 8, 2010 19:25

    Hi gurpreet,

    finally I managed to reproduce your error. I put me/photos request into right text input that expects image bytes on return… FAIL ;-)
    I created two text inputs there in my example. One is to return JSON string data the other to return binary data. The most of the calls return JSON (me, me/photos), but there are also some that returns binary data – e.g. bytes of profile picture (me/picture). In your case (me/photos) you expect JSON data (some list of urls and other stuff), please insert your request into left input field and click left call button.

    In order to get logged users you have to use fql like:
    SELECT uid, name, pic_small FROM user WHERE online_presence IN (‘active’, ‘idle’) AND uid IN (SELECT uid2 FROM friend WHERE uid1 = $MYUSERID)

  14. Jozef Chúťka May 8, 2010 19:31

    Maz, I did not have tried that myself, but it should work. You have to:
    - make POST request on /PROFILE_ID/feed
    - add message variable parameter
    more here http://developers.facebook.com/docs/api#publishing

  15. Ângela Costa May 10, 2010 15:46

    Thanks!!!!!

  16. John Tipton May 10, 2010 19:57

    Jozef,

    I was wondering, if you had a Flex project I could download. I’m having a issue with some of the browser-AS communication, and it would be great to see the entire project.

    Thanks,

    JT
    Interactive Evangelist
    Dell Inc.

  17. Josef Salyer May 10, 2010 22:05

    I put together an example app at git hub for those struggling with facebook and air:
    http://github.com/josefsalyer/Facebook-Flex-Example-App

  18. Jozef Chúťka May 11, 2010 09:32

    Hi John,
    the entire project (flex framework v3.5) consists of:
    - app.mxml (source in the article)
    - FacebookOAuthGraph.as (linked in the article)
    - FacebookOAuthGraphEvent.as (linked in the article)
    - html wrapper file view-source:http://blog.yoz.sk/examples/FacebookOAuthGraph/
    - swfobject.js view-source:http://blog.yoz.sk/examples/FacebookOAuthGraph/js/swfobject.js
    - callback.html (source in the article)

    thats it thats all, there is nothing else
    if you have issues with JS to AS communication please follow this comment:
    http://blog.yoz.sk/2010/05/facebook-graph-api-and-oauth-2-and-flash/#comment-1757

  19. Jk_ May 11, 2010 11:43

    Hi Jozef,

    Thanks for this great class. Like Kevin I tried to convert your Flex example into a fully working Flash example.

    However, I experience some problem with the call function where the callComplete() is never fired.

    It seems that the request is endless.
    [i]“Transfering data from graph.facebook.com”[/i]

    My Flash demo page : http://www.thelbc.be/test/fb/index2.html

    My As file : http://www.thelbc.be/test/fb/FacebookConnector.as

    Thanks in advance for your feedback.

    Jk_

  20. Jozef Chúťka May 11, 2010 12:12

    hi Jk,
    facebook service may be down or may timeout, however, my best recommendetaion is to use proxy software to watch all your requests/responds, that helps you with debugging a lot. Brilliant one is http://www.charlesproxy.com/ .

  21. josep May 11, 2010 12:43

    hello.

    This my sound a stupid question but … how do i do to get the data from the byteArray. Example : how do i get the “name” of the logged user.

    Thans

  22. Jozef Chúťka May 11, 2010 12:59

    josep, you do not need binary call for that, try:

    facebook.call(“me”).addEventListener(FacebookOAuthGraphEvent.DATA, callComplete);
    function callComplete(event:FacebookOAuthGraphEvent):void
    {
    trace(event.data.name);
    }

  23. Jk May 11, 2010 13:51

    Hi Jozef,

    Thanks for the Charles Proxy link. It looks like something very useful indeed.

    It works properly now.

    Greetings from Belgium.

  24. Jk May 11, 2010 14:55

    Hi Jozef,

    Me again. I wonder how I could publish to user wall using me/feed/.

    Where should I specify the content of the message, link and description?

    Cheers,

  25. Jozef Chúťka May 11, 2010 16:32
  26. Chris May 11, 2010 17:00

    Hi Jozef,

    Thanks for putting the work into this – it’s really useful in trying to unravel the mess FB drop on us.

    Seems that me/feed and me/home etc won’t work due to permissions – you’d need to add in read_stream as well most of the time, as the posts won’t be public. Facebook probably saw that you had this working so added that in to keep the fun going…

    Thanks

  27. josep May 11, 2010 17:12

    @Jozef Chúťka

    Thanks… i haven’t thought that well..

    Cheers.
    Josep

  28. josep May 11, 2010 18:24

    hello again.
    I was trying to publish something in my wall with this code:

    public function post(id:String, msg:String):void
    {

    var loader:URLLoader = new URLLoader ();
    var request:URLRequest = new URLRequest (apiPath + ‘/’ +id+ ‘/feed’);

    request.method= URLRequestMethod.POST;
    var variables:URLVariables = new URLVariables();
    variables.message=msg;
    request.data=variables;

    loader.load(request);
    loader.addEventListener(Event.COMPLETE, on_complete);

    }

    But something is not woking.
    Any help?

  29. John Tipton May 11, 2010 19:03

    Thanks, Jozef, I appreciate the quick response.

    Cheers!

    JT

  30. Jozef Chúťka May 11, 2010 23:16

    @josep, do not forget to include
    variables.access_token = token;
    all other code seems to be ok, use charles proxy to debug request and let us know

  31. Murtuza May 12, 2010 05:33

    Hello Jozef, great stuff with the code and thanks for sharing it. I have tried to implement a flash version of it.
    The thing is i get this error when i check my response to any calls made to me/whatever
    {
    “error”: {
    “type”: “OAuthException”,
    “message”: “You must use https:// when passing an access token”
    }
    }
    My current scenario is facebook application running on facebook itself. so its not a desktop mode but website and developer mode on. I have also left out the hash portion of the mxml as confirmconnection seems to be running anyway.
    Can you tell me what i may be doing wrong?

    Thanks!
    MT

  32. Jozef Chúťka May 12, 2010 12:04

    hello Murtuza,
    I have noticed today morning, facebook changing rules on the fly again. Please read “update” part of this article I have just added

  33. Jk_ May 12, 2010 13:58

    Hi Jozef,

    Thanks for the update!

    It’s a sad news.

  34. Jozef Chúťka May 12, 2010 23:22

    anyone, please support this bug with your vote, on official facebook bugzilla, it may help:
    http://bugs.developers.facebook.com/show_bug.cgi?id=10055

  35. Murtuza May 13, 2010 10:16

    Thanks for the update mate. I find that there is one other method to connect other than the sever side script proxy method which is to use the Facebook Javascript api to proxy the calls. This would reduce any load on your own server and just pass queries and results to and fro the swf to facebook. I guess it is heading back to the old days.

  36. Jk_ May 13, 2010 18:02

    Hi Murtuza,

    I created a small demo page where I use the JS api with As3 using ExternalInterface.

    http://www.thelbc.be/test/fb/index.html

    If you are curious of the JS api, you should definitely read this awesome tutorial by Mahmud Ahsan.

    Hope it helps.

    Jk_

  37. Jk_ May 13, 2010 18:04

    Link to the article

    Sorry, it seems that i forgot to close a tag in my previous post.

  38. daweed May 14, 2010 15:18

    Hello jk_

    Can you please give more information on how you mix the as3 and js API.
    Doing the connection on facebook throught as3 connect, and then doing call on open graph methods through js s?
    Thanks a lot

  39. Ellen Sundh May 14, 2010 16:07

    Please support this bug with your vote, on official facebook bugzilla, it may help:
    http://bugs.developers.facebook.com/show_bug.cgi?id=10055

  40. Jozef Chúťka May 14, 2010 21:31

    reply from facebook devs to the bugged issue:
    Jeff Bowen 2010-05-14 11:32:12
    Thanks for the report. We are looking into this.

    thanks for voting folks :-) I hope things get solved soon

  41. Jk May 15, 2010 17:19

    Hi daweed,

    In fact, I only use the JS Facebook SDK.

    The connection between as3 and js is done with ExternalInterface.

    I would prefer use only as3 but with the recent changes in the facebook crossdomain policy, I had to figure out something else.

    Cheers.

    Jk

  42. Brmm May 16, 2010 01:05

    @Jk

    How do you fire the FB.login function with ExternalInterface? When I try to do it, the popup with the fb connect doesn’t show up because it doesn’t get fired by a clickEvent in js, how did you get around it?

    grts

  43. Jk May 16, 2010 14:12

    @Brmm

    You should definitely read this article of Mahmud Ahsan. So far it’s the best tutorial on the JS Facebook SDK.

    Just browser my JS code and you will find what you need.

    - http://www.thelbc.be/test/fb/myfunction.js

    - http://www.thelbc.be/test/fb/index.html (check the source)

    Let me know if it helps.

  44. zanuka May 17, 2010 12:56

    I’m weeks away from launching my app on Facebook and this info is very helpful. It’s a shame it all has to be so hacky. I’d love to see someone publish a straightforward tutorial or best practices doc. Seems like the JS api and external interface are still the way to go.

  45. Dan May 18, 2010 09:56

    ——- Comment #12 From Jeff Bowen 2010-05-17 13:56:45 ——-

    This should be fixed with Tuesday’s push. Stay tuned.

    :O

  46. Chris May 18, 2010 10:26

    They’ve said it should be fixed by Tuesday. At least I didn’t spend the past week writing a version to handle it all through JS. Oh wait, yes I did…

  47. Dan May 18, 2010 10:41

    atleast I didnt :P

  48. Jk May 18, 2010 13:14

    @Chris

    We all did! :D

  49. Chris May 18, 2010 16:59

    Yay! It’s done!

    https://graph.facebook.com/crossdomain.xml

    Now we can rewrite everything and wait for the excitement of finding out what they’ll change next!

  50. Dan May 18, 2010 23:37

    anyone tried out – http://code.google.com/p/fbas/ … and how the hell (noob question proberbly) do i get my domain to run SSL … or https ?

  51. Jozef Chúťka May 19, 2010 09:31

    good news everyone – secure is false
    https://graph.facebook.com/crossdomain.xml
    and application is working again!

  52. Chris May 19, 2010 10:57

    I’m not sure if it’s a load balancing issue or what, but it has now gone back to secure=”true” for me on all of the connections I’m trying. Seems they’re having some problems with Tuesday’s release so it it may take a little while to cement this fix.

  53. Jozef Chúťka May 19, 2010 11:24

    Chris,
    try clear https://graph.facebook.com/crossdomain.xml from your browser cache
    for now it contains <allow-access-from domain=”*” secure=”false”/> for me … but it may be that there is an old version of .xml somewhere in network heaven

  54. Chris May 19, 2010 12:25

    Yeah, it’s not a caching issue – from work it’s now updated to “false”, but from my home it’s still “true”. I think the only sensible solution might be to have a version that can switch between JS and AS calls, just for future proofing as far as possible. Which is annoying!

  55. Nick May 19, 2010 18:57

    For some reason the javascript function doesn’t seem to be calling the confirmConnection function (getting a null token value when I trace it out from inside the class). I did everything exactly as you did up there w/ swf object…any ideas?

  56. Jozef Chúťka May 19, 2010 20:25

    Hi Nick,
    - first please clear browser cache and let me know if this example works for you, if not tell me what browser you use
    - download latest http://classes.yoz.sk/sk/yoz/net/FacebookOAuthGraph.as class and copy latest application code (change clientId and redirectURI), define all the necessary settings for your facebook app
    - upload your app so callback.html and .swf file and wrapper file are on the same domain
    (as defined in facebook settings) now tell me what works and what do not, does the popup open? does it close itself after success auth?

  57. Dan May 19, 2010 21:11

    Hey JC … I got a question, I use your classes in Flash (thx for sharing btw).

    If I do a call like http://graph.facebook.com/{uid}/feed the result come back are in JSON, do I need to decode them with JSON, or ? Because I don’t see you doing that :)

    I’m asking because I’m a bit confused the Flash vs Flex

  58. Jozef Chúťka May 19, 2010 21:23

    Hi Dan,
    am I JC? :D well ok,
    anyway good question, I am glad you noticed that because I forgot to mention this in the article. well this may not be obvious but you can get decoded data via event.data

    example call(“me”), returns:
    private function callComplete(event:FacebookOAuthGraphEvent):void
    {
    trace(event.data.name);
    }

    just make sure you dont try to decode ByteArray (eg. me/picture)

  59. Dan May 19, 2010 22:19

    Hehe ye your JC … got a bit lazy with the typing (sorry)

    I got another question, what would be easiest:

    I’m trying to load alot of profiles pictures for a Flash Facebook game, do I reference all thru individual calls to /{uid}/picture and load them with ByteArray, or … can i load them like I would load external pictures normally

    var image:URLRequest = new URLRequest (“http://graph.facebook.com/{uid}/picture”);

    because i think i saw somewhere that its possible to batch load multiple profile pictures thru one api call, i just cant find it anymore.

    And now im a bit confused what way to do it :)

  60. greeshma May 20, 2010 02:27

    Hi Jozef,

    I am new to flash/as3/xml.i am trying to understand the code.i am trying to create a button when user clicks on it message will goto their feed.can you please tell me in steps like how to run this code from flash cs4.

  61. Jozef Chúťka May 20, 2010 11:48

    @Dan, that reminds me C.J. from BayWatch :D
    I would use Loader class with normal URLrequest, no need to go through secured nor authorized requests for this as long as profile picture is public

  62. Jozef Chúťka May 20, 2010 12:08

    @greeshma you should follow the actionscript code used in the example, it is more less the shortest possible way to achieve what you need.
    1. create facebook instance and check for saved token
    2. use user interaction (mouse click) to dispatch popup via facebook.connect() – user interaction needed so blocker will allow your popup to open
    3. prepare a listener for FacebookOAuthGraphEvent.AUTHORIZED that is dispatched after callback
    4. now you are connected (access token defined)
    5. use facebook.call() function to do whatever you want

  63. Jessica May 21, 2010 01:38

    Hi! You definitely did an awesome work here! I was totally clueless on how to implement the new changes until I read this article.

    I have this situation, I have a canvas application, so I’m looking for a way the users don’t have to click on a “Connect” button like you do on a website outside facebook.

    I tried modifying the checkSavedToken() function on FacebookOAuthGraph to this:
    public function checkSavedToken():Boolean
    {
    if(!savedSession.data.token){
    return false;
    }else{
    var token:String = savedSession.data.token;
    var loader:URLLoader = call(“me”, null, “”, token);
    var type:String = FacebookOAuthGraphEvent.DATA;
    loader.addEventListener(type, checkSavedTokenComplete);
    return true;
    }
    }

    And then init() to this:
    private function init():void
    {
    facebook.clientId = clientId;
    facebook.redirectURI = redirectURI;
    facebook.scope = scope;
    facebook.useSecuredPath = true;
    facebook.addEventListener(FacebookOAuthGraphEvent.AUTHORIZED, authorized);
    var iftoken:Boolean = facebook.checkSavedToken();
    if (iftoken == false){
    connect();
    }
    log.text += “checkSavedToken()\n”;
    }

    But then Firefox blocks the popup! :(
    The app can’t connect to facebook unless I allow the popup, so I can’t use this.

    Any ideas? I really don’t want to have a “connect” button on a canvas app :(

  64. Jozef Chúťka May 21, 2010 10:05

    @greeshma you are messing the whole thing up :( … are you trying to use official ActionScript Facebook classes with my one? that will just not work

  65. Jozef Chúťka May 21, 2010 10:21

    @Jessica There is no need to change the code of FacebookOAuthGraph class, if you need changes, please extend it with your custom class, I made all methods in public or protected namespace so there should not be problem with it. PopUp blocker does exactly what you have described, it block popups that are not invoked by user interaction, you will not make this work but you dont even need it!!!

    when using canvas page (i suggest iframe):
    - before generating flash, redirect from your html (via javascript or php) to authorization url
    https://graph.facebook.com/oauth/authorize?client_id=XXX&redirect_uri=BACKTOMYHTML&type=user_agent&scope=XXX
    - when it returns to your html it contains access_token (same as our callback.html)
    - now it is time to generate flash and pass this token into your flash via eg. flashvars.token
    - in actionscript handle flashvar params and pass token into facebook.confirmConnection(“#access_token=” + token)
    - now you should get connected

  66. Jk_ May 21, 2010 19:01

    It works like a charm!

    Thanks Jozef for the updates.

    Greetings from Belgium.

  67. Jessica May 22, 2010 01:47

    You’re genius! Just let me try it and I’ll tell you how it worked out, thanx a million :)

  68. lars May 23, 2010 12:50

    thanks, works just great! anyway due to all that changes i’m a little bit confused now :)

    actually i’m missing a complete application setup incl. app settings and stuff. like checking for
    “is logged in”, “has app”, redirect, login, check token, check if extended permissions granted and stuff. somekind of “framework”-basic-setup-tutorial would be handy.

    in my case i totally dropped the as3 api and just use this handy class for the new extended permissions, what i’m missing now is the initial setup (verify login, redirect to login, check permission). also i would love to integrate the js sdk into this, because i still prefer having popups when posting stuff to a user’s wall instead of automatically doing so (even if the user granted his permission to do so).

    anyone sucessfully this class and the js sdk via external interface already? if the user is logged in via opengraph, do i need to re-login him via the js sdk? is it the bad facebook documentation or is it me that’s causing this confusion? :)

    thanks: lars

  69. lars May 23, 2010 13:12

    just noticed i do not get any permission popup on safari (windows) or chrome (windows). ie and firefox do work…

  70. Jozef Chúťka May 23, 2010 20:31

    hi lars,
    thanks for your feedback ;)
    - what exactly do you mean by “i do not get permission popup”? is your popup blocked? or does it close itself in a second? I use chrome as my main browser and do not have any problems with it. once you grant permissions to the app, you are not asked to regrant them with next login (facebook behaviour)
    - I know there are some things missing in the class, that is why its meant to be abstract. It contains just the minimal working code by purpose. I have left a lot of room for extending there, eg. to verify login override confirmConnection() method, add some simple call (me) and handle the result (or error)… there is a lot of things everyone needs to handle differently so why making this code any longer?
    - I would also like to hear someone mount this class with js. if so please let me know. I guess the js makes the same api calls (with access_token), so to push token from flash to js (or vice versa) should be enough to make them work both

  71. Lars May 23, 2010 20:57

    hi jozef,

    no popup blocker on chrome or safari. it seems there’s an js error on the ext interface call. actually i’m logged in on firefox and try chrome and safari while the logged-on-session in firefox is running.

    safari error console reports: Unsafe JavaScript attempt to access frame with URL (my facebook app url) from frame with URL (my own server with url pars passed). Domains, protocols and ports must match.

    safari on windows and safari on osx report this error…

    thanks: lars

  72. Jozef Chúťka May 24, 2010 09:45

    lars, does my example work for you? if so, please follow all the steps one by one so your app will get also working. I do not have safari but this seems like xss, you may have bad callback url defined or something like that.

  73. Morten Knutsen May 24, 2010 18:17

    Wow.. now it seems that facebook is changing the crossdomain.xml file at random.
    I am developing a login function for a site using your code (great stuff, btw – thanks!), but suddenly it got unstable.
    When I checked the https://graph.facebook.com/crossdomain.xml file, is’s changing at random for a very short time (1-2 seconds), removing the ‘secure=”false”/’ part, so that https would be needed.
    I REALLY hope Facebook will stabilize this.
    Just thought i would post this comment to help explain the problem to anyone experiencing the same thing.

  74. Morten Knutsen May 24, 2010 20:46

    Can you help me figure out a way to log the user out with a function in flash?
    I can’t figure out how to call the javascript (FB.logout) needed to do this. So when I try to use the login a second time, there is no way of changing the user, without logging out of facebook in another window, or deleting the application permittoin in facebook.
    It would be great if you could give me a hint fro this!

  75. Jozef Chúťka May 24, 2010 20:49

    @Morten, if this issue persist even after clearing your browser cache, pleas report it as a bug

  76. Jozef Chúťka May 24, 2010 20:52

    @Morten to log-out user, it is enough to clear the SharedObject (contains access_token)

  77. Morten Knutsen May 24, 2010 21:36

    Hi, thanks for the quick response!
    I tried clearing the SharedObject allready, but it did not seem to work. I’ve not worked with this before, so I might be doing something wrong.. Here is my code, I have tried a bunch of different stuff, to see if any of it works, but no luck:

    public function logOut(){
    var name:String = “FacebookOauthGraph” + clientId;
    var _savedSession = SharedObject.getLocal(name);
    trace(“before loging out: ” + _savedSession.data.token);
    _savedSession.clear();
    trace(“after loging out: ” + savedSession.data.token);
    }

    I put the code inside your class (sorry for the mess). But it seems like the reference to the token is still there, as it logs me back in automatically when calling the connect method again. The before/after trace tells me that the tokens are gone after clearing.
    Any ideas?

  78. Jozef Chúťka May 25, 2010 10:09

    @Morten
    now I see what you are trying to do. There is no logout method in graph api (as far as I know), you can logout user from facebook using javascript api:
    FB.Connect.logoutAndRedirect(“http://mydomain/logoutcallback.html”);
    or logout in another window (as you have mentioned)

    If you want to just disconnect – clear token data from my class you can use:
    public function disconnect():void
    {
    savedSession.clear();
    protected::token = “”;
    protected::authorized = false;
    }

  79. @Jey May 25, 2010 15:06

    Tks for this post, very usefull.
    However, how can we get large picture ?
    Because we have to write something like that :me/picture?type=large
    Is there a solution ?
    tks

  80. Jozef Chúťka May 25, 2010 15:47

    @Jey you should do it this way:
    var data:URLVariables = new URLVariables();
    data.type = “large”
    call(“me/picture”, data);

  81. @Jey May 25, 2010 17:30

    Tks for the update !

  82. Sean May 27, 2010 09:13

    Hey Jozef, these classes are invaluable – great work! I’m having difficulties posting an image bytearray to a FB album,
    What should I post in the URLVariables?

  83. Jozef Chúťka May 27, 2010 10:12

    Hi Sean,
    I do not have much time to test it but it should be possible on “/ALBUM_ID/photos” + supplying image file and message params
    http://developers.facebook.com/docs/api section “Publishing to Facebook”
    http://forum.developers.facebook.com/viewtopic.php?pid=227012

  84. Sean May 27, 2010 13:40

    Thank you posting that forum post, made it alot easier figuring it out.

    This is how we did it, implemented in to your class.
    Maybe there is a way of using normal urlloader for this aswell.

    /**
    * MultipartURLLoader by Eugene Zatepyakin can be found here: http://bit.ly/9wx4q7
    */
    public function uploadImageCall(path:String,ba:ByteArray,message:String,token:String=null):MultipartURLLoader
    {
    var mpLoader:MultipartURLLoader = new MultipartURLLoader();

    mpLoader.addVariable(‘message’, message);
    mpLoader.addFile(ba, “image.jpg”, “image”);
    loaderAddListeners(mpLoader.loader);
    mpLoader.load(apiSecuredPath + ‘/’+ path + “&access_token=”+ _token);
    return mpLoader;
    }

    Thanks alot for pushing us in the right direction.

  85. ancle May 27, 2010 14:36

    very strange things… all worked, but me/photos return:
    {“data”: [ ]}

    but full string like https://graph.facebook.com/me/photos?access_token=2227470867|2.g57ZbEd7tdwxzCsXDAa4Og__.3600.1274965200-1152055895|sBLebRBpQIjzQW_kPj7sdg2iFkA. returned normal fulled data.

    WHY? ;)

  86. Jozef Chúťka May 27, 2010 14:39

    @Sean thnx for posting working solution

  87. ancle May 27, 2010 14:39

    Is not permission problem because me/albums worked ok.

  88. Jozef Chúťka May 27, 2010 14:42

    @ancle because api does not know who you are without sending access_token, even if it would, your photos may be private, that is why you need access_token

  89. ancle May 27, 2010 16:30

    and i can update my status message whitout access_token?

    i try connect to fb with different way… now i see my acess_token inside my swf (with iframe cavnas).
    i see “authorized” message too, but me/photos still empty…

    i need to get call() with my token manualy or it’s automatic?

  90. ancle May 27, 2010 16:41

    me/albums work
    me/feed work
    changeStatus work

    but me/photos – empty… i don’t fking understand ;)

  91. znt May 27, 2010 16:59

    same here, me/photos not working. Tried the left box for me/photos but it returns empty result. I don’t think privacy is an issue because I set all my albums to “everyone can see” mode.

    Can you please explain what I need to do to see the photo data? Actually maybe updating the article or writing a new one about photos (simple photo gallery app) would be so awesome!

    Thanks for the article anyways, it helped a lot.

  92. ancle May 27, 2010 17:36
  93. Jozef Chúťka May 27, 2010 17:44

    @znt, @ancle now I see what is the problem, facebook changed rules again. I have removed and readded my app and I also see empty arrays for me/photos. Now, it is time to introduce “user_photo_video_tags” permission. I have already added it into my app, so please remove your browser cache, refresh app and click connect button (even if you are connected) and grant the permission, results should be ok again

  94. ancle May 27, 2010 17:53

    yes, it look like solution, but… still not working ;)

    maybe cache or something… i try it from another pc…

  95. znt May 27, 2010 19:29

    Thanks for quick reply jozef, here’s what happened.

    I cleared browser cache (firefox), refreshed the page, connected to facebook, application asked for new permissions, granted. => “me/photos” not working.

    Fired up google chrome, came to this page, connected to facebook. => not working.

    Sat on a different pc, came to this page, connected to facebook => not working.

    Logged out, logged in with another facebook account (sister’s), came to this page, connected to facebook, granted all permissions to the application. => “me/photos” working for sister’s account.

    So what may be the problem? Is there an option to regrant/refresh all the permissions to application? maybe the application is still prohibited from accessing my photos?

  96. znt May 27, 2010 19:38

    Hey I just tried something and it worked.

    From facebook dev forum:
    http://forum.developers.facebook.com/viewtopic.php?pid=223727

    “In all my attempts searching I couldn’t figure out what the issue was. ahdang you may have missed that any photos that you aren’t tagged in won’t show still.

    In order to successfully do this you must retrieve the albums, then the pictures from that object. For example:

    https://graph.facebook.com/me/albums

    then call…

    http://graph.facebook.com//photos
    https://graph.facebook.com//

    Read this on facebook, then tagged myself in my photos. The photos I was tagged was returned when “me/photos” was called.

    Then I copy pasted an album id from “me/albums” and used “album_id/photos” command in the left box. Voila, all photos in that album returned as a result.

    I think you should update your article about this.

    Thanks for great work anyways.

  97. ancle May 28, 2010 00:24

    From another pc, after new autorization me/photos worked.

    Jozef thanks, i’ll go to create AMAZING application.

  98. Sean May 28, 2010 11:25

    Hey thanks for the props, though I have to clarify that it was
    “barryels” from http://forum.developers.facebook.com/viewtopic.php?pid=227012 who came up with the solution I just implemented it with your OAuthGraph class.

    I can only confirm it working with users own albums.
    Haven’t figured out how to – 1, send image bytearray via “/feed”, only the string gets passed to your feed.
    2 – you will get a “stream error” when trying to upload images to a fanpage’s public gallery.

  99. Dan May 28, 2010 13:51

    why am I getting a strange window within a window when doing a iFrame canvas app :( ?

  100. Dan May 28, 2010 13:51

    i ofc mean iFrame with a iFrame inside

  101. Dan May 29, 2010 11:10
  102. @Jey May 31, 2010 11:53

    I would like to know why i can’t have the same informations about my profil when i call : “me” with this flash application and when i click on this link : https://graph.facebook.com/me in the selection part of: http://developers.facebook.com/docs/api (this method allow to get full information)

  103. Jozef Chúťka May 31, 2010 12:29

    @Jey its due to permissions, I guess the app behind call from developers.facebook.com has granted all permissions from you (fb made it so). this app just a few of them.

  104. @Jey May 31, 2010 12:57

    Damn it ! :)
    But thx
    May be there is a solution to get all permissions?
    I have searched in parameters of my application but there is nothing about that…

  105. Jozef Chúťka May 31, 2010 13:36

    @Jey here you can find list of all possible permissions
    http://developers.facebook.com/docs/authentication/permissions
    put all you need into scope:
    private var scope:String = “publish_stream,user_photos,user_photo_video_tags”;

  106. @Jey May 31, 2010 13:51

    Thks a lot, i have already founded and i was back to post these informations about authorization.
    Some of authorizatios about profil
    user_location ,email ,user_relationships, user_religion_politics, user_birthday, user_photos ,read_stream ,user_status, user_about_me”…….

    Thanks for the feedback !

  107. Jessica May 31, 2010 18:19

    Hello, well I’m back to tell you how things are working out for me trying to make my iframe app work.

    I tried to implement the steps of “How can I use this class in my iframe canvas page?” but I’m afraid that I had the same problem described here http://forum.developers.facebook.com/viewtopic.php?pid=228774

    The good news is that someone posted a working solution to this(answers #13 from jasek2)that consists on having an index.php which only function is to make a redirect and having the rest of the application in another folder, the redirect uri MUST be to that folder, e.g. http://apps.facebook.com/appname/callback/ .Then you can retrieve a var called ‘code’ and ask for ‘acess_token’ using your ‘code’,'client_id’, ‘redirect_uri’ and ‘client_secret’. Once you get your ‘acess_token’ you can send it via flashvars to the flex app. This is how I did it, it’s a mix of Jozef’s exellent app and the solution of facebook forum:

    Index.php on http://yourserver/appname/:
    <?
    echo "”;
    echo “window.open(‘https://graph.facebook.com/oauth/authorize?client_id=xxxxx&redirect_uri=http://apps.facebook.com/appname/callback/&scope=xxxxx’, ‘_parent’, ”)”;
    echo ” “;
    ?>

    Index.php on http://yourserver/appname/callback:
    <?php
    $code = $_GET["code"];
    $token = file_get_contents('https://graph.facebook.com/oauth/access_token?client_id=xxxxx&client_secret=xxxxx&redirect_uri=http://apps.facebook.com/appname/callback/&code='.$code.'');

    echo 'var flashVars = {access_token:”‘.$token.’”};var params = {wmode:”opaque”,allowScriptAccess: “sameDomain”};var attributes = {id: “FacebookOAuthGraphTest”,name: “FacebookOAuthGraphTest”};swfobject.embedSWF(“myswf.swf”, “flashDiv”, “600″, “400″, “10.0.0″, “expressInstall.swf”, flashVars, params, attributes);’;

    ?>

    On Flex app:
    public var myToken:String;

    private function initfb():void
    {
    facebook.clientId = clientId;
    facebook.redirectURI = redirectURI;
    facebook.scope = scope;
    facebook.useSecuredPath = true;
    facebook.addEventListener(FacebookOAuthGraphEvent.AUTHORIZED, authorized);
    facebook.checkSavedToken();

    myToken=this.loaderInfo.parameters.access_token;
    facebook.confirmConnection(myToken);
    }

    —–
    This is working for me BUT on the same thread on facebook forum (answer #21) someone is asking about how safe is to pass the client_secret on the url. I have the same doubt but I see no other way to get the acess_token. Even facebook suggest passing the client_secret on the url here http://developers.facebook.com/docs/authentication/ :

    * After the user authorizes your application, we redirect the user back to the redirect URI you specified with a verification string in the argument code, which can be exchanged for an oauth access token. Exchange it for an access token by fetching https://graph.facebook.com/oauth/access_token. Pass the exact same redirect_uri as in the previous step:

    https://graph.facebook.com/oauth/access_token?
    client_id=…&
    redirect_uri=http://www.example.com/oauth_redirect&
    client_secret=…&
    code=…

    I’m really concerned about safety, so even if this is working, I don’t know how risky is to pass the client_secret on the url. What do you think? What do you recommend? :S

  108. Randall June 1, 2010 11:45

    Hello Jozef,

    This is a very helpful class and much better than the old way of doing things. It seems I have a problem, however. I get the following error AFTER the authentication goes through:

    Invalid redirect_uri: The Facebook Connect cross-domain receiver URL (http://randallknapp.com/aliens/callback.html) must have the application’s Connect URL () as a prefix. You can configure the Connect URL in the Application Settings Editor.

    Here is what I am doing. My directory on my server (http://randallknapp.com/aliens) looks like this:
    - callback.html
    - Project1.swf
    - index.html
    - expressinstall.swf
    - js/swfobject.js

    and in my application settings, under Authentication, my Post-Authorize Callback URL is “http://randallknapp.com/aliens/callback.html” and when I call the connect method of your class I set redirectURI = “http://randallknapp.com/aliens/callback.html”.

    I don’t know what is going on…

  109. Jozef Chúťka June 1, 2010 13:25

    @Randall make sure to read whole article, especialy the facebook settings part. You do not need Post-Authorize Callback URL, just setup other correctly (Connect URL…).

  110. Pieter Michels June 1, 2010 13:52

    I extended your class and override the ‘call’ function and added this line:

    path = path.indexOf(“?”) > -1 ? path + “&” : path;

    it allows you to call methods like: /me?metadata=1 and /?ids=me,cocacola,eastpak

    might be helpful.

  111. Jozef Chúťka June 1, 2010 15:18

    @Pieter ok, or you can do it with URLVariables … read FAQ / “How to add request parameters into my call?”

  112. James Deagle June 2, 2010 20:47

    Found an error or maybe its just me. Click Connect -> when the facebook login pop up appears click cancel..

    Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
    at Error$/throwError()
    at flash.net::URLVariables/decode()
    at flash.net::URLVariables()
    at sk.yoz.net::FacebookOAuthGraph/hashToToken()
    at sk.yoz.net::FacebookOAuthGraph/confirmConnection()
    at Function/http://adobe.com/AS3/2006/builtin::apply()
    at flash.external::ExternalInterface$/_callIn()
    at ()

  113. [...] graph api integration into your flash app. Before continue reading, make sure you understand the previous article. Due to huge interest, I am adding codes that makes your flash app working with graph api within [...]

  114. Marc Pelland June 3, 2010 17:37

    Just FYI, I don’t know if anyone figured this out yet (didn’t read through all the posts). I noticed that some people seemed to be having an issue with the events. From what I can tell, the event may be getting fired before it is listened for.

  115. Jozef Chúťka June 3, 2010 20:18

    @James ok I will take a look at it
    @Marc I have been doing some minor changes lately… anyway can you replicate the issues?

  116. Marc Pelland June 4, 2010 01:58

    @Jozef I added a quick fix for the issue in my version of the code.

    all that i needed to do was add a couple extra (optional) params to the call function so that the listener can be added to it prior to the event firing. There are a couple ways to do it, this was just the quickest for me to get going with.

    public function call(path:String, data:URLVariables=null, method:String=”", token:String=null, ARG_type:String = “”, ARG_callback:Function = null):URLLoader {
    if(!data)
    data = new URLVariables();
    data.access_token = token || public::token;

    var request:URLRequest = new URLRequest(apiPath + ‘/’ + path);
    request.data = data;
    request.method = method || URLRequestMethod.GET;

    var loader:URLLoader = new URLLoader();
    loaderAddListeners(loader);

    if (ARG_callback != null) loader.addEventListener(ARG_type, ARG_callback);

    loader.load(request);
    return loader;
    }

    so then my call looks as follows:

    public function checkSavedToken():void
    {

    if(!savedSession.data.token)
    return;

    var token:String = savedSession.data.token;
    var type:String = FacebookOAuthGraphEvent.DATA;

    var loader:URLLoader = call(“me”, null, “”, token, type, checkSavedTokenComplete);

    }

  117. Jozef Chúťka June 4, 2010 10:01

    @Marc nice workaround, anyway I would recomend to extend FacebookOAuthGraph class instead of rewriting it, I have also made some changes in this class, so please update

  118. Jozef Chúťka June 4, 2010 10:15

    @James ok mate, I have just fixed the error issue. please update

  119. James Deagle June 4, 2010 19:03

    Thank you very much. I will give it a try!

  120. Donovan June 6, 2010 03:42

    Hi folks. I’m seeing some issues regarding the public and protected namespaces for the token and authorized vars. I’m assuming this is set up for FLEX only? Also, I know this has seen quite a bit of activity (for obvious reasons) over the course of the couple weeks, and if anyone has an AS3 only based example using these awesome classes that would rock!

  121. Jozef Chúťka June 6, 2010 23:14

    Hi Donovan, I will take a look at it

  122. Donovan June 7, 2010 04:48

    Thanks Jozef! Feel free to shoot me an email if you have any suggestions. I’ll be playing around with this this week and let you know if I find anything worth sharing. Cheers

  123. Jozef Chúťka June 7, 2010 10:32

    @Donovan, updated, please download latest FacebookOAuthGraph, its compatible with flash authoring tool compiler. http://blog.yoz.sk/examples/FacebookOAuthGraph/cs.as

  124. @Jey June 10, 2010 20:57

    Hi !
    I have one question about the new class, what is exactly :
    ” parameters ”
    in —> facebook.autoConnect(parameters);

    I have check it s an object who can have : parameters.session
    But to start i have to declare this object “parameter”

  125. Jozef Chúťka June 10, 2010 22:59

    Hi Jey, parameters are flashvars:
    - in flex project you can use application.parameters
    - in as project it is something like stage.root.loaderInfo.parameters

    …when using facebook iframe ( http://blog.yoz.sk/2010/06/authorizing-iframe-facebook-applications-for-graph-api/ ) , you receive valid session as GET parameter

  126. myrddin June 11, 2010 12:49

    Hi,

    Thanks for your tutorial. Great !
    One thing : You need compile in Flash 10, in Flash 9, it doesn’t work on Internet Explorer.
    Enjoy !

  127. Carl June 12, 2010 16:31

    Hey Jozef!

    Thank’s alot for these great classes, really helps alot.

    I have one problem though, I’m trying to detect if a user declines(presses cancel/don’t allow) in the facebook-allow-popup. I noticed there is an UNAUTHORIZED-event in your eventclass but is is never dispatched. I tried to deduce where to dispatch it myself but I couldn’t figure it out.

    Any idéas?

    /Carl

  128. Jozef Chúťka June 14, 2010 11:57

    Hi Carl,
    1. when user clicks cancel confirmConnection() method is called with empty argument – catch it there
    2. you are right, I did not implemented UNAUTHORIZED dispatch. I think graph API does not support logout method, but you can use “auth.logout” method from REST API. try something like:
    facebook.call(“method/auth.logout”, null, URLRequestMethod.GET, null, “https://api.facebook.com”);

  129. Carl June 14, 2010 13:30

    Hi again. Thanks for taking the time to help. Although, this doesn’t seem to work. I do it like this;

    public function confirmConnection(hash:String):void
    {
    if(hash && hash != “”)
    verifyToken(hashToToken(hash));
    else {
    var type:String = FacebookOAuthGraphEvent.UNAUTHORIZED;
    dispatchEvent(new FacebookOAuthGraphEvent(type));
    }
    }

    facebook = new FacebookOAuthGraph(); facebook.addEventListener(FacebookOAuthGraphEvent.AUTHORIZED, authorized);
    facebook.addEventListener(FacebookOAuthGraphEvent.UNAUTHORIZED, unAuthorized);

    But the UNAUTHORIZED-event never seem to be dispatched, at least my listener doesn’t pick it up. The AUTHORIZED-event works just fine though..

  130. Jozef Chúťka June 14, 2010 13:44

    you are almost there Carl, now all you have to do is to debug what comes in hash variable when cancel is clicked

  131. Carl June 14, 2010 15:16

    Bah, the only problem was my darn computer being somewhat retarded. Worked as a charm as soon as I rebooted. Sorry about that and thanks again. :)

  132. josep June 15, 2010 12:59

    Hello guys.

    Does any one ever tried to implement a button the button with this example. I getting desperate with this issue because i trying to render some xfbml on my html page, but nothing is being showed.
    The code i trying is …

    thanks

  133. Jozef Chúťka June 15, 2010 13:11

    @josep again pls, what should your button do?

  134. josep June 15, 2010 13:54

    sorry the code is ,

    but i´m almost sure that it is the wrong way to go

  135. josep June 15, 2010 13:55

    The button should add my application to a tab on the user profile.

    http://wiki.developers.facebook.com/index.php/Fb:add-profile-tab

  136. Jozef Chúťka June 15, 2010 14:30

    @josep how does this relate to the actionscript class?

  137. Nick June 16, 2010 19:22

    @Jozef Chúťka

    On line 031 of your example, you are referring to a variable called parameters in your autoConnect function, but this is undefined. What should I put here? I hacked it to work but I’m getting a popup after the user has connected, trying to avoid this. Thank you.

  138. Jozef Chúťka June 16, 2010 21:29

    @Nick parameters are flashvars: stage.root.loaderInfo.parameters

  139. Paulo June 21, 2010 10:39

    Hi Josef,

    I’ve being trying to load a profile picture using your class but i’m not able to do that.
    i’m using like this:

    loader = facebook.call(“me/picture”);
    loader.dataFormat = URLLoaderDataFormat.BINARY;
    loader.addEventListener(FBGraphEvents.DATA, callComplete);

    the connecting part is working fine.

    but on the “callComplete(event:FBGraphEvents)” i try to trace this values:

    trace(event.rawData) //this traces weirds chars (should be ok)
    trace(event.rawData is ByteArray) //this traces false
    trace(event.rawData as ByteArray) //this traces null

    then if i try to use the loadBytes here, it won’t work.

    Do you know what could be happening? Am I doing something worng?

    Thank you for your time. =)

  140. Jozef Chúťka June 21, 2010 11:46

    @Paulo, please use callComplete() from my example. It works. Maybe the FBGraphEvents class you use is problematic. FacebookOAuthGraphEvent works fine…

  141. Paulo June 21, 2010 13:11

    @Jozef, thanks a lot for your feedback. it’s weird because i just renamed the classes. All other method are still working fine just the binary one is having problem. But anyway i downloaded it again and used the default name and it worked. Later i will try to figure out what could’ve happened with my code =)

    Thanks again.

  142. jag June 21, 2010 20:08

    Hi Jozef:
    Is it possible to use the Graph API to “like” a page via AS3? The issue I’m encountering is that my site is completely Flash based while the only utilities provided by Facebook are HTML/Javascript (e.g. their “Like” Button).

    Thanks in advance,

    jaglavek

  143. markval June 22, 2010 01:11

    When you have no picture it will FAIL!

    Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation: http://blog.yoz.sk/examples/FacebookOAuthGraph/FacebookOAuthGraphTest.swf?v=2 cannot load data from http://static.ak.fbcdn.net/rsrc.php/z5HB7/hash/ecyu2wwn.gif.
    at sk.yoz.net::FacebookOAuthGraph/call()
    at FacebookOAuthGraphTest/call()
    at FacebookOAuthGraphTest/___FacebookOAuthGraphTest_Button4_click()

  144. Jozef Chúťka June 22, 2010 09:14

    @jag, you can not use graph API to like stuff, there is no method for that. even by testing like request:
    href: http://www.facebook.com/pages/***
    node_type: page
    edge_type: like
    page_id: 12345
    action_text
    now_connected: true
    nctr[_mod]: connect
    post_form_id: 123ABF***********
    fb_dtsg: TAfAJ
    post_form_id_source: AsyncRequest

    post_form_id is some static required parameter that you can not guess

  145. Jozef Chúťka June 22, 2010 09:19

    @markval override loaderAddListeners() and loaderRemoveListeners() and add security error handler like so:
    type = SecurityErrorEvent.SECURITY_ERROR;
    loader.addEventListener(type, loaderSecurityError);

  146. [...] The Facebook Graph API article becomes pretty popular and a lot of developers keep asking me to publish some practices I use, I [...]

  147. jag June 22, 2010 16:18

    Hi Josef. Thank you for taking the time to respond to my (and the many other) questions. Your help is greatly appreciated.

    Sincerely,
    Jaglavek

  148. John June 24, 2010 01:21

    Thanks for this.

    Anyone know a way to use this to popup a feed dialog so the stream publish message is editable by the user. Like this example?

    http://fbrell.com/fb.ui/stream.publish

  149. Jozef Chúťka June 24, 2010 11:18

    Hi John, the dialog you are refering to, is a part of facebook javascript sdk. I do not use js sdk in my class, its pure actionscript. If you want dialog box, you are free to create one inside your flash app, with your graphics, your text input etc.

  150. Ilya June 24, 2010 11:40

    hi,

    When I am running your app I am getting this error from Facebook: “An error occurred. Please try again later.”

    Any ideas?

  151. Jozef Chúťka June 24, 2010 12:04

    @Ilya I guess it is one of the facebook’s api common error, please try again later.

  152. Ilya June 24, 2010 13:25

    Yeah defiantly, the question is there any thing I can do to fix it?

  153. Ilya June 24, 2010 13:48

    Oh nvm, I forgot the init() when moving to flash builder…

  154. Ilya June 24, 2010 14:24

    Hi again,

    Now I got some other error, I can log in this time, and it even redirect to the redirectURI, but then nothing, the authorized function is not executed.

  155. Toby Skinner June 24, 2010 19:09

    Thanks for posting on this, I found your examples useful and have managed to get Graph API auth & calls working now. Thanks again.

  156. John June 24, 2010 19:12

    That’s what I figured. Thanks Jozef.

  157. Jozef Chúťka June 24, 2010 23:36

    @Ilya, is your callback url on the same domain as original app? if not use advanced callback
    http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/

  158. Ben Bee June 26, 2010 14:34

    Hey Jozef,

    Evewn though you explained it I cannot develop my app locally because the callback only works on the domain.

    Where do you get the access_token value and where do you copy it into the code to publish again?

    thnx a lot BB

  159. Ben Bee June 27, 2010 00:34

    Hi Jozef,

    I got it to work after I inserted this little function and button:

    protected function showToken():void {
    Alert.show(facebook.token);
    }

    And then inserte your code snippet from the FAQ into the init() of the main.mxml file.

    As this however implies that I have to copy and paste the token String all the time, I tried your Advanced Crossdomain Working Authorization from your other article here: http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/comment-page-1/#comment-2313

    But somehow I cannot get this to work properly. I am not so sure if I generated the correct Callback.swf. Could you possibly post yours or tell me how to create it the right way, please?

    I will keep you posted on my progress.
    Anyways, thanks for your seriously great effort here!
    BB

  160. Ilya June 27, 2010 11:25

    Hi Jozef,

    The callback URL are the same as domain, the only difference is that I am using flex 4, I have no idea what may cost this problem. What information should I provide you so you can help me?

  161. Alex Winx June 27, 2010 17:37
  162. Jozef Chúťka June 28, 2010 11:01

    Hi Ben Bee, to make it work locally, please read http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/ and advanced callback part. I have fixed link to Callbkac.swf, thanx for noticing that. Now I read your next post, do you have problems with LocalConnection? What OS / flash player you use? In mac + 10.0 is LocalConnection somehow broken, fixed in 10.1…

  163. Jozef Chúťka June 28, 2010 11:06

    Ilya, does it work with my app? if so, make sure you use latest class versions + check your facebook app settings

  164. per June 28, 2010 15:55

    Hi
    Really cool classes =) Though I have wierd problem using the MultipartURLLoader to upload a image to an album. I get Sandbox violations #2048 error. I don’t know what is missing because the FacebookOAuthGraph loads both the http://graph.facebook.com/crossdomain.xml and the https://graph.facebook.com/crossdomain.xml. I don’t get the error trying to get autorization or when I want to use the FacebookOAuthGraph::call function to get and set user data in facebook. I don’t know if it has something to with sending a bytearray and new retrictions from the flash player itself? I am currently using Flash debugger version 10,1,53,64.

    //Per Borin

  165. Jozef Chúťka June 28, 2010 16:34

    Hi per, what are your call() parameters? Is your request domain/path really https://graph.facebook.com/... or is it https://api.facebook.com/... ?

  166. per June 28, 2010 17:07

    Yeah man, I load both http://graph.facebook.com/crossdomain.xml and https://graph.facebook.com/crossdomain.xml. When I am authorised with the FacebookOAuthGraph.as I set a button visible and only then you’re able to save an image through a mouse click. To save the image I use the example code:

    var theAlbumID:String = “”;
    var theJpegEncoder:JPGEncoder = new JPGEncoder(60);
    var theUserImageByteArray:ByteArray = new ByteArray();
    theUserImageByteArray = theJpegEncoder.encode(this._theImage.bitmapData);

    this._theMultipartLoader.addVariable(‘message’, ‘Some image text!’);
    this._theMultipartLoader.addFile(theUserImageByteArray, “image.jpg”, “image”);
    this._theMultipartLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.onSecurityError );
    this._theMultipartLoader.load(“https://graph.facebook.com/”+ theAlbumID +”/photos?access_token=”+ this._theFacebook.token );

    I noticed it is working on the Internet Explorer where I am not using a debugger version, I don’t know, I am just little bit confused. If you want to you can see the example at http://www.polopon.com/flash/facebookTest/TakeSthlmFacebookFlash.html

  167. Jozef Chúťka June 28, 2010 17:31

    I did not used MultipartLoader myself yet, but i guess it does make POST request, so isnt the missing album id the case? Does your app request correct permissions?
    https://graph.facebook.com//photos?access_token=...
    … try contacting Sean http://www.seanhak.net/ for correct solution

  168. per June 28, 2010 17:47

    Thanks for the fast replies, if you leave the album empty it will create a new photoalbum, at least it does it in flash player in Internet Explorer. Okey I try to contact him. =)

  169. devu June 28, 2010 20:46

    Hi guys. That method seems to be promising. However from time I’ve got Flash 10.1 installed. Very often I see Security Sandbox errors when I am dealing with .NET services and I’ve noticed here as well.

    In the example provided above Authentication is okay,
    Call me works
    But call binary giving me Sandbox security Error.

    On the example above(next me my post) same issue.

    > onSecurityError:: [SecurityErrorEvent type="securityError" bubbles=false cancelable=false eventPhase=2 text="Error #2048: Security Sandbox Violation: http://www.polopon.com/flash/facebookTest/FacebookConnectGraph.swf can't read data from https://graph.facebook.com//photos?access_token=135050026512805|2.8mk1am4QxV_uk73X_gueNw__.3600.1277755200-1321209476|7KiCC_PanRazH77yzmtw0ELIfjg.."]

  170. Francsico chong June 28, 2010 22:24

    Hi Is there a way to implement a “i Like” button with your class, by the way u are my hero! thanks for this class!

  171. Jozef Chúťka June 29, 2010 11:46

    Hi Francsico, sorry, but impossible for now… please read updated faq

  172. Jozef Chúťka June 29, 2010 11:49

    Hi devu,
    I use latest release FP 10,1,53,64 / debug version / Mozilla / win xp, and no errors for me with binary calls. what is your version / type / os?

  173. per June 29, 2010 15:55

    I solved the problem when I got a message from Sean. The problem is that I did not set the url correct and got an “unvalid path string” error, as you said yesterday Jozef =) I was trying to set up a new album to anything with the API. But when I changed the URL to me/photos instead of just blank everything worked in both IE Flash player and the debugger player Firefox. Why it did worked in IE player before I can’t explaine. Here is the code that worked for me.

    var theJpegEncoder:JPGEncoder = new JPGEncoder(90);
    var theUserImageByteArray:ByteArray = new ByteArray();
    theUserImageByteArray = theJpegEncoder.encode(this._theImage.bitmapData);
    this._theMultipartLoader.addVariable(‘message’, ‘This is a message!’);
    this._theMultipartLoader.addFile(theUserImageByteArray, “image.jpg”, “image”);
    this._theMultipartLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.onSecurityError );

    this._theMultipartLoader.load( “https://graph.facebook.com/me/photos?access_token=”+ this._theFacebook.token );

    Thank you for the great help and fast replies =)

    //Per

  174. Jk_ June 29, 2010 18:45

    Hi there,

    I wonder if anyone else have trouble to make the FacebookOAuthGraph works with IE6.

    I know IE6 (and all IE versions) is a pain in the ass but…

    Let me know if it works for you.

    Thanks in advance.

    Jk_

  175. Carol X June 29, 2010 20:51

    @Jk_
    Yes, I can’t get it to work on IE, any version.
    There’s a bug filed on the issue, see if it is related to your problem and if it is, please vote so we can have Facebook check the issue:
    http://bugs.developers.facebook.com/show_bug.cgi?id=10631

  176. francisco Chong June 29, 2010 22:31

    Hi Jozef, thanks for your response, was hoping for a solution.
    Anyways i have another question, regarding the implementation of autoconnect, where did u declared the variable parameters? or what values should this variable have, thanks in advance.

    Im using the flash IDE for my project, and i dont see where in your flex code its declared, i would like to be able to autoconnect if you already have a access token.

    Regards,
    Francisco Chong

  177. Jk_ June 30, 2010 07:00

    @Carol X

    Hi Carol,

    It’s weird because everything works fine for me on IE7 & IE8.

    However, your test app doesn’t work on my IE8 either…

    Could you please try this app with your version : http://www.thelbc.be/test/fb/

    Let me know.

    Cheers,

    Jk_

  178. Jozef Chúťka June 30, 2010 09:36

    Jk_, Carol X funny, my app works for me in IE8… I have FP 10,1,53,64 debug / ActiveX / IE8 / win xp

  179. Jozef Chúťka June 30, 2010 09:49

    Hi francisco Chong,
    parameters are flashvars (stage.root.loaderInfo.parameters) , you can use parametrs variable in flex Application element

  180. Jk_ June 30, 2010 12:48

    @Jozef > It works in IE8 for me too! The problem for me it’s IE6… I will just advice my client to download Google Chrome :D

  181. Jk_ June 30, 2010 13:59

    In fact I got a status 304 for the callback.html instead of a 200

    HTTP/1.1 304 Not Modified

    Date:Wed, 30 Jun 2010 11:45:07 GMT
    Server:Apache
    ETag:”2ac5ef9-1ea-485d92083311e”
    Vary:Accept-Encoding

  182. Francisco Chong July 2, 2010 01:27

    Hi again Jozef thank you for your replies, i noticed that u added that to your flex code, but im still having trouble making it autoConnect, is there a way for me to retrieve the parameters.session object variable with your class, maybe a method?

    i noticed when i open your app, in a new window you have flashvars = { }, since there is nothing there flash just throws an error saying its undefined or null, and locks.

    Thank you very much for this class, i hope there is some kind of solution, oh btw im kinda looking for a way to force a “like” within flash hehe, when i have it ready ill share the method.

    Thanks in advance,
    Fch

  183. Jozef Chúťka July 2, 2010 12:13

    @Francisco, parameters (flashvars) are only utilizable with facebook iframe app, because facebook pushes GET parameter session to your iframe that you can use for connect, please read
    http://blog.yoz.sk/2010/06/authorizing-iframe-facebook-applications-for-graph-api/
    when you pass parameters without session, the class tries to connect with stored (SharedObject) session.

  184. John July 6, 2010 23:51

    Has anyone had issues with the callback not firing on Safari Mac/Win? No matter what I do the FacebookOAuthGraphEvent.AUTHORIZED callback never comes back.

  185. Jozef Chúťka July 7, 2010 10:07

    @John, Maz kind of has on mac/ff:
    http://blog.yoz.sk/2010/05/facebook-graph-api-and-oauth-2-and-flash/#comment-1779
    are you able to debug javascript and actionscript? where does your scripts fails? Is ExternalInterface called from the callback.html javascript?

  186. Rapha July 8, 2010 00:13

    Hi Jozef!

    Thanks not only by the great library, but also to explain how auth works with the new Facebook API.
    I’m using your library now, to build a feature where users can download a wallpaper composed with profile pictures of friends.

    But when I try to draw the bitmapData I got the error:
    “SecurityError: Error #2122: Security sandbox violation: BitmapData.draw”

    All the images where loaded like:

    var thumbURL:String = ‘http://graph.facebook.com//picture?type=small’;
    var loader:Loader = new Loader();
    var context:LoaderContext = new LoaderContext(true, ApplicationDomain.currentDomain);
    loader.load(new URLRequest(thumbURL), context);

    Any idea?
    Thanks in advance!
    Best regards

  187. Jozef Chúťka July 8, 2010 10:22

    Hi Rapha,
    I guess this is due to the fact that your request is redirected to a different domain. check this out:
    request:
    http://graph.facebook.com/jozefchutka/picture
    response:
    HTTP/1.1 302 Found
    Location http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs621.snc3/27350_1215645368_8115_q.jpg

    the actual photo exist on profile.ak.fbcdn.net domain, you should try to parse targeting domain and request crossdomain from http://profile.ak.fbcdn.net/crossdomain.xml

  188. [...] it all good, this guy, Jozef Chúťka, figured it all up. His code is pretty good and the example gives you everything you need to get [...]

  189. Rapha July 9, 2010 01:27

    Hi Jozef,
    Thanks for your quickly reply!
    I’ve tried to request the crossdomain.xml file, but it doesn’t work.
    But then, I’ve created a proxy php file to load the image from that address and works.
    It’s not a good solution, but I’ve no more time left to research more about this subject right now.
    Later I’ll check this out and post the result here.
    Thanks!

  190. Daniel July 9, 2010 18:56

    hi Jozef

    thanks for this – you continue to do amazing work

    Cheers

  191. Jozef Chúťka July 12, 2010 09:17

    @Rapha, yes it shuould work just fine with proxy
    @Daniel, thank you ;)

  192. Daniel July 12, 2010 11:43

    hi Josef

    To get the access-token to work I had to unescape the string rather than just do the regex replace : i.e.

    JSON.encode({ access_token:String(unescape(String(“139972822682…

    cheers

  193. Jason July 12, 2010 11:45

    Thank-you so much for your tutorial and scripts. They have been so useful for a project I have just completed! Just wondering if you have every taken the code 1 step further and made the popup a modal, rather than a new window (Facebook Connect style)? Thanks again!

  194. Jozef Chúťka July 12, 2010 13:25

    @Jason, unable to make it modal, facebook does not let you open its content in iframe anymore (clickjacking)

  195. Torben July 13, 2010 19:58

    Hi Jozef

    I can’t get posting to feeds working.
    I tried your example from the FAQ but nothing happens.

    I had it working using the old AS3 API from Adobe.

    Any ideas ?

  196. Sa. July 14, 2010 14:29

    I tried your example and i receive this error…
    {
    “error”: {
    “type”: “OAuthException”,
    “message”: “Invalid redirect_uri: The Facebook Connect cross-domain receiver URL (http://www.mysite.com/fb/callback.html) must have the application’s Connect URL () as a prefix. You can configure the Connect URL in the Application Settings Editor.”
    }
    }
    Any idea?
    Thanks in advance!
    Best regards

  197. Jozef Chúťka July 14, 2010 15:27

    Hi Torben,
    could you please try change your status from my app? if this works for you, make sure you grant correct permission with your app and try using code from my app

  198. Jozef Chúťka July 14, 2010 15:31

    @Sa, I think you have used your own app (http://www.mysite.com/fb/callback.html is not defined in my one), facebook is trying to tell you that you have to setup facebook connect url correctly, please read “Additional information about my facebook app” section, if you try to debug your own app from desktop, read http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/ section “Advanced Crossdomain Working Authorization”

  199. Torben July 14, 2010 17:43

    I am able to change status with your app on this page.

    I’m pretty sure I grant the correct permission.
    I’m also able to post to my Wall with your app here:
    http://www.thelbc.be/test/fb/index.html
    My popup looks excactly the same.

    For posting on the wall don’t I just need to ask for “publish_stream” in the scope ?

    This is my code for publishing:

    ———
    var fbAttachment : Object = {};
    fbAttachment.media = [{"name":"www.tandfix.dk", "type":"image", "src":src, "href":"http://www.google.com"}];

    fbAttachment.caption = “my caption”;
    fbAttachment.description = “my description”;

    var data:URLVariables = new URLVariables();
    data.message = message;
    //// data.attachment = fbAttachment;
    data.attachment = JSON.encode(fbAttachment);
    facebook.post(“method/stream.publish”, data);

  200. Torben July 14, 2010 17:47

    …and the src in the media is a valid url to an image BTW :o )

  201. Jozef Chúťka July 15, 2010 10:03

    Torben, yes publish_stream is enough. But, are you sure you are using my library? Coz I am somehow unfamiliar with your facebook.post() function…

  202. Torben July 15, 2010 11:58

    Sorry, that should have been facebook.call(“method/stream.publish”, data);

    Don’t know what the problem is then. How do I debug those calls to facebook ?

  203. Jozef Chúťka July 15, 2010 13:03

    ok than, I see few problems there:
    1. you should use post method
    2. https://api.facebook.com as 5th parameter for call
    anyway… you can use the working example from:
    http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/ , section Publishing Feeds / Publish feed with image

  204. Torben July 15, 2010 15:23

    I’m closing in on something here.

    After calling connect() the callback funtion confirmConnection is fired.
    But as far as I can see that should call verifyToken() which in turn should call verifyTokenSuccess() which should dispatch the FacebookOAuthGraphEvent.AUTHORIZED event.

    But I’m not getting that event.
    verifyTokenSuccess() doesn’t get called ?

    When is it actually authorized ?

  205. Jozef Chúťka July 15, 2010 15:45

    Torben does your browser open new popup window when clicking on connect? this popup opens facebook and after successful verification calls your callback.html where is the javascript that calls verifyToken(). does this happen to you? does it happen for you in my app? if no what is your os and browser. If this works for you in my app and does not in your one, please makse sure to read whole article again, there must be something you are doing wrong. There are many questions answered in faq and other in comments. Please go through the stuff and you will get your issues resolved sooner

  206. Torben July 15, 2010 16:08

    But callback.html calls:
    window.opener.confirmFacebookConnection(window.location.hash);

    …isn’t that a javascript function in my index.html it’s trying to call ?….I don’t have that and I can’t see that you do either.

  207. Jozef Chúťka July 15, 2010 16:13

    js function confirmFacebookConnection() is injected from actionscript when connecting

  208. Torben July 15, 2010 16:20

    OK, good. I don’t get any errors there and verifyToken() does get called. I know that but the problem is that verifyTokenSuccess() never does.

  209. Torben July 15, 2010 17:08

    Getting closer.

    verifyToken() calls the call() method which tries to load https://graph.facebook.com/me with the token as a parameter.

    But I get an IOError on that which is weird beacuse if I paste that url with the token I got traced back directly in a new browser window I do get the info on me back with no errors.

  210. Jozef Chúťka July 15, 2010 17:21

    Torben, search IOError in this page and you may find your answer…, even in FAQ:
    This example app works with Internet Explorer, but my one results in Error #2032
    Please complie your app to Flash Player 10 (or later). It should fix this issue. Credits goes to Garcimore , thnx

  211. Torben July 15, 2010 18:00

    I am compiling to v10.

    Thanks for all your help – I’m kinda lost now.

    This example: http://www.thelbc.be/test/fb/index.html
    Do I understand correctly that it only uses JS via ExternalInterface and not the FacebookOAuthGraph at all ?

    If yes, is all the JS I need in the js file ?

    Thank you

  212. Carol X. July 15, 2010 23:19

    Compiling the app to flash 10 didn’t work for me.
    I’ve been checking this page regularly in the hope that someone has stumbled upon the same issue and found a solution, since the bug filed in facebook is kinda abandoned

  213. Jozef Chúťka July 16, 2010 09:48

    @Torben, @Carol X.,
    I confirm that I can reproduce the error from the bug post, but while the requests from my app works for me in IE, the same requests (https://graph.facebook.com/me?access_token=XYZ) from e.g. this app http://apps.facebook.com/carolices/ results in some connection problem. It seems like it must be some kind of facebook issue / facebook app settings that is causing it. there is not much i can do about it, just make sure your app settings looks something like this
    http://blog.yoz.sk/examples/FacebookOAuthGraph/settings.png

  214. Dionysius July 16, 2010 22:01

    first thanks for sharing this! Real good work! I already extended your Class and Implemented several Facebook graph features. Everything works quite fine as far as Facebook let you interact. But there is one thing that works different in every App I created to your Demo: My Access Token expires after I log out of Facebook and your Token keeps on working. My Tokens worked for 30 minutes after log out when I switch the App mode from Web to Desktop and certainly longer when I add the offline_access scope. But you don’t ask for offline access and It keeps on working for hours.

    What do I miss?

  215. Jason Redhawk July 17, 2010 17:44

    Thanks Jozef, this is great work. Being a bit old school, I’m not much of a Flex developer and I was able to convert most of your example so it would work using the Flash IDE. However, I can’t seem to figure out how to retrieve the hash confirmation string back from the callback.html popup. Would you have an example that works just through the Flash IDE? Appreciate any help you can offer.

    ps. I think it’s time for me to learn to program in Flex.

  216. Jozef Chúťka July 19, 2010 10:18

    @Dionysiusm thnx, I guess facebook does not unvalidate access_token that fast after logging out, in this class the token is persistently stored in sharedobject, and while facebook api responds with a valid result (for this token) your app may not notice your logout

  217. Jozef Chúťka July 19, 2010 10:24

    @Jason Redhawkm thank you, please download latest FacebookOAuthGraph, its compatible with flash authoring tool compiler. http://blog.yoz.sk/examples/FacebookOAuthGraph/cs.as … in general, when clicking on “connect” button, actionscript injects javascript into wrapping html. callback holds reference for its opener (wrapping html) and is able to call the javascript function that pushes hash back into the main flash, make sure to have allowScriptAccess and name + id attributes for flash.

  218. Dionysius July 19, 2010 14:52

    Thanks for your reply. Thats how I proceed actually because I’m extending your class. For testing purpose I created a button wich always do the same call with the sharedObject Token. As long as I’m logged in everything works fine, but as far as I log out I’m getting a “400 Bad Request” response. The same call keeps on working in your Demo App above.

    I really have no Idea why this is happening. Maybe its some app setting thing.

  219. Jozef Chúťka July 20, 2010 09:39

    @Dionysius yes it may be some app settings, see http://blog.yoz.sk/examples/FacebookOAuthGraph/settings.png

  220. Carol X. July 21, 2010 02:46

    Hi

    My application suddenly started to work on IE after no change from my part, and I almost threw a party… but it didn’t take long to find out it only worked for my own user.

    Then I came back here and saw you shared your application settings, thanks! But I tried them out and they did not help.

    Now I noticed it has nothing to do with broser version or flash player version. The application works on the same machine for user 1, but it doesn’t work for user 2.

    The only differences between the two accounts are:
    - id for account 1 (working) has 9 digits, while for account 2 (not working) it is longer, 15 digits
    - account 1 (working) is the application developer, account 2 (not working) is not, but the app is not in sandbox mode (I’ll try adding someone to the developer list to see if it works)

    Seems more likely that the problem is in the id length, what do you think?

  221. Francisco Chong July 22, 2010 04:14

    Hi again Jozef thanks to your class i have solved so much on this FB graph project im working on, but now i got some kind of an issue with Macs, seems the authorization popup window never loads for ppl on a mac and probably behind a firewall, do you have any idea why this could happen?

    Works perfectly on any PC, but when its loaded on MAC, it seems to try to connect for a long period of time ending in not being able to connect at all.

  222. Jozef Chúťka July 22, 2010 09:32

    @Francisco, do i get it right – the popup is opened and the request to secured facebook page blocked?

  223. Jozef Chúťka July 22, 2010 09:40

    @Carol do you have issues with the app also with other browsers than ie? Long (64bit bigint) ID could be problem while actionscript uses 32bit integers, but IDs are handled (e.g. returned from /me) as strings so it should not do any harm

  224. Steve July 22, 2010 14:07

    Hey Thanks for this just what i was looking for.

    Popup blocking from some browsers setup was a bit of a pain but did a hacky fix around. that worked for my purposes

    Might be interesting to some, basically I create a temporary html text link to do the same window open command, if its blocked automatically

    Modified within your connect() method of facebookOAuthGraph

    + ‘var success = window.open(“‘ + url + ‘”, “‘ + name + ‘”, “‘ + props + ‘”);’
    + ‘if(!success){‘
    // create a new div element position on page above/near around the flash
    //set innerhtml to have a text link – which does the window.open method

    etc etc

  225. Jozef Chúťka July 22, 2010 16:00

    @Steve very nice solution, thank you for sharing

  226. eva July 27, 2010 14:01

    I have tried your example application from here: http://blog.yoz.sk/2010/05/facebook-graph-api-and-oauth-2-and-flash/. The login works, but the label near the connect button will remain “not connected” even if i copy paste the access token in the hash textbox. The verifyTokenSuccess function will be NOT called. I am new in Actionscpript. The application runs in adobe flex bulider. I have debugged it, after clicking the “add hash” button, the acces token is good, this function: function(event:FacebookOAuthGraphEvent):void
    {
    EventDispatcher(event.currentTarget)
    .removeEventListener(event.type, arguments.callee);
    verifyTokenSuccess(event, token);
    });

    never runs.
    I didnt change the application id (private var clientId:String = “268718683475″;), I think this isnt a problem.

  227. Jozef Chúťka July 27, 2010 14:18

    @eva I am somehow unable to reproduce this issue, I am using xp/ie8 and authorization process is smooth (eva is win7/ie?). Did you click allow button on the opened facebook popup? Could you test it on another facebook account?

  228. John Lee July 28, 2010 12:25

    hi Jozef, thank u for your impressions.

    now, i still have some problem with working in IE8 (Error #2032)
    Firefox and Chrome work fine

    many people say publish to flash 10.0.0 will be fine..
    but it doesnt work..

    Here is my file
    http://chialung.dlinkddns.com/NEWFB/OAuth.rar
    i write the code in fla file and use Flash CS4

  229. Jozef Chúťka July 28, 2010 12:29

    @John, Hi, this is definitely a facebook bug, please vote for http://bugs.developers.facebook.com/show_bug.cgi?id=10631 … I have all my 100 votes on it right now

  230. John Lee July 28, 2010 13:15

    Thank you for help~~^^
    so this bug didnt fixed yet…..ok.

    anyway, your example work so perfect, its work in IE6 to IE8.
    and i saw other example, some example can run, some example fail
    what happend to it??
    use Flex make flash is more better?

  231. Jozef Chúťka July 28, 2010 13:27

    @John you are welcome. make sure you have correct settings http://blog.yoz.sk/examples/FacebookOAuthGraph/settings.png , if the issue remains it is facebook/ie8 related and I am unable to handle that from flash player, some apps works, some do not, some works for some users only… Flex vs. Flash does not behave different in this context.

  232. John Lee July 29, 2010 04:02

    After I tried this setting, it doesnt work again.
    anyway…i just hope facebook quick fix it now.
    thank you for your help.^^

  233. Tryg Nord July 29, 2010 23:47

    Thank you for the great source!

    I have a swf that publishes a game score to the user’s facebook wall.
    In Safari, it behaves perfectly. I’ve already added a javascript timeout for the confirmFacebookConnection(), which made it work in Firefox, but Internet Explorer still gets stalled on the callback.html.

    Has anyone had this issue and resolved it?

    Would there be an issue with loading the swf from a Content Delivery Network, instead of having it sit in the same directory as the callback.html?

  234. Tryg Nord July 30, 2010 00:11

    Could this also be related to the IE facebook bug you mentioned? I put 100 votes on it.

  235. Jozef Chúťka July 30, 2010 10:56

    Hi @Tryg, if your original html wrapper for main.swf exists on the same domain as callback.html, the javascript should be executed without security issues. I did not tried it within different directories:browsers, but I believe it does not violate crossdomain. Does my example work for your IE? .. If issues persist, try advanced callback from http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/ . If you tell me where the flow collapses (javascript/actionscript line?), I can tell you wheter it is related to the facebook IE bug or not. Even if it were not related, your votes are very useful ;) thank you

  236. Carol X. August 4, 2010 02:25

    Hey Jozef

    Yes, I only experienced the problem in IE and long ids…
    A Facebook employee sent me a proposed fix (where I sould use POST instead of GET for all requests). I thought it would work, but I still get the error with long IDs. =(

  237. Jozef Chúťka August 4, 2010 10:23

    Hi Carol, thank you for reporting, I have updated the article. it seems like ie issue with content-type:application/json header. I hope it soon get resolved by fb devs:
    http://bugs.developers.facebook.com/show_bug.cgi?id=10631

  238. Zeke August 10, 2010 08:26

    Not sure if this will help anyone else, but I was facing a huge problem with IE 6-8. My flash iframe app just wouldn’t connect to retrieve the access token. After hours of trying, I just tried changing my app settings. Under migrations > OAuth 2.0 for Canvas (beta) > disabled. Amazingly that fixed everything.

  239. shammi August 11, 2010 20:07

    hi, i am in big trouble. i need help with session .logout() it is not working. how do i make this work
    facebook.call(“method/auth.logout”, null, URLRequestMethod.GET, null, “https://api.facebook.com”); it is not a website it is an air application. i want users to be able to logout to other can login. i use desktopsessionhelper and is there a work around using the clear() flash cookie. i want when i user logout he needs to loginagain. but here it justs login without asking for username and password.

  240. tom August 11, 2010 22:15

    Hi, tkx for all those precious informations. I have a question though:
    do you have any idea of how to get that same application that you have here in a tab ? (profile tab or fan page tab)
    The facebook documentation explicitly says that they need the user to make an action on the tab to actually allow us to get user id for example. When loading a flash movie in a tab, the user has to activate it in order to use it (needed action from user), but I can’t find a way to use the facebook api the same way you are doing here in an application tab.
    If you have any idea or clue, plz feel free to drop a line. I might be totally “wrong” or blind but I just can’t get it to work.
    tkx!

  241. Jozef Chúťka August 12, 2010 10:46

    hi shammi, what exactly is desktopsessionhelper? you can not make user login on your site, there is no such api method “method/auth.logout” in rest api. however you can subscribe with javascript sdk to FB.Event.subscribe (auth.logout) but my class does not use javascript sdk

  242. Jozef Chúťka August 12, 2010 10:52

    hi tom, I have not worked with tabs yet, but I guess you have to use FBML for tab content:
    http://blogs.reseo.com/2009/10/how-to-create-custom-facebook-tabs-and.html
    by using FBML fb:swf, all fb_sig_ params should be passed into your flash (I guess also access_token based on your app settings):
    http://developers.facebook.com/docs/reference/fbml/swf

  243. tom August 12, 2010 16:37

    Jozef, tkx for your quick answer, I found the “problem”, I got a session_key instead of a token, just had to activate the “Canvas Session Parameter” in the migration tab of the application parameters form.
    tkx again for your support.

  244. shammi August 12, 2010 23:20

    hi, i dont have to wory about logout anymore i am using ur api now. i had to delete all the code of reset API . which stoped working two days ago.
    now my only problem is i want users to upload picture to a specific album.
    the MultipartURLLoader i am using an air application and i get stream error.
    albumid = 214446590807
    when using https://graph.facebook.com/album_id/photos?access_token=djfjdsjjf

    hey thanks for ur quick response earlier.

  245. shammi August 12, 2010 23:24

    i tried using this
    https://graph.facebook.com/me/photos?access_token=something

    and using multipathurlloader
    i get some error like this
    Error #2044: Unhandled ioError:. text=Error #2032:

    https://graph.facebook.com/me/photos?access_token=?access_token=125852647452490%7C2.sbLpfy_dIArZWtSELT61_A__.86400.1281736800-527865807%7CZCLmr3200dLMCdHmXV6fy12qck0.&expires_in=88708/

    i dont have links to seans blogs. i am making a desktop air application in as3. so do u think that i have to load something else too?

  246. shammi August 13, 2010 00:12

    ok i seems to have fixed this. it works now i was posting it with two ?? so the error. it’s amazing how this works.

    Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: https://graph.facebook.com/312707920807/photos?access_token?access_token=125852647452490%7C2.POlryieX5fcLqUgIne9X_A__.86400.1281740400-527865807%7CAmhdFvLeMTdDJwbBvc8Id4VDe34.&expires_in=89971/

    yea everything good now. i am able to post it to a specific album https://graph.facebook.com/“+ 312707920807+”/photos”. every one use the graph API it will solve all ur problems relating to empty album data and logout.

  247. Jozef Chúťka August 13, 2010 09:38

    @shammi, Im glad you did it ;)

  248. Adam August 18, 2010 17:51

    Hi Jozef,

    Excellent tutorial – I have a strange problem when calling:
    call([my id]/photos)

    It used to work in that it returned all the photos I have most recently been tagged in, but for some reason now just returns an empty “data” array…

    I think it may have something to do with my access token or something. The call works when I enter it into your flex app. Here is the call my flash is making:
    https://graph.facebook.com/508157048/photos?access%5Ftoken=124898804200049%7C2%2EXpW7hFZjOPgvF6flBsaaNg%5F%5F%2E3600%2E1282150800%2D508157048%7CNXXGx3AKt0qUPaeHU1697qqV0xc%2E

    Any help would be very much appreciated!

    Cheers
    Adam

  249. Jozef Chúťka August 18, 2010 17:57

    Hi Adam, i guess its due to missing permissions, try “user_photos,user_photo_video_tags”

  250. Adam August 18, 2010 18:16

    Thanks for that Jozef – I had ‘user_photos’ but not user_photo_video_tags’ added – this seems to have made the difference.

    Cheers
    Adam

  251. PVieira August 24, 2010 12:02

    Is it possible to get the person e-mail?

  252. Jozef Chúťka August 24, 2010 12:52

    @PVieira yes, extended permission “email”, more here http://developers.facebook.com/docs/authentication/permissions

  253. [...] Facebook Graph API & OAuth 2.0 & Flash (update) [...]

Leave a comment

Please be polite and on topic. Your e-mail will never be published.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes