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
App Domain:              yoz.sk
Website / Site URL:      http://blog.yoz.sk/examples/FacebookOAuthGraph/
App on FB / Canvas URL:  http://blog.yoz.sk/examples/FacebookOAuthGraph/facebook.php?a=b
Page Tab / Page Tab URL: http://blog.yoz.sk/examples/FacebookOAuthGraph/facebook.html?
Canvas type:             iframe
Developer Mode:          Off
App Type:                Native/Desktop
Sandbox Mode:            Disabled
Remove Deprecated APIs:  Enabled
signed_request for Canvas: Enabled
Timezone-less events:    Enabled
Encrypted Access Token:  Enabled
...other Migrations:     Disabled

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

Is there a .fla version available?

Yes, there is a simple working Flash CS4 archive available for download (.fla + all sources). The demo connects the facebook application and once connected, it uploads generated picture into photo album.

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.

I can not make it run in my Mac-Safari sonfiguration

It seems there is a bug in Safari on Mac that does not let you open popup via ExternalInterface. You should use navigateToURL() in that case. Credits goes to Beans, thank you. More instructions here.

var js:String = "return window.navigator.userAgent.indexOf('Safari') > -1);"
if(ExternalInterface.call("function(){" + js + "}")){
   // safari specific code

448 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=&#039;.$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) […]

  254. jake September 1, 2010 18:55

    Jk_ .. could you send me your example.. i am trying to do what you did exacly but i am having a ton of issues

  255. […] It does not provide login authentication as there are many other libraries available for this purpose and really…why re-invent the wheel? Some great examples are from Big Spaceship and Jozef Chúťka. […]

  256. André Vendramini September 3, 2010 23:04

    Hi,

    First, congrats for your work! It´s amazing =)

    I´m trying to solve a connection problem with IE6. It seems that facebook doesn´t pass the token to it. I´m putting an “alert(hash)” on callback.html and just on IE6 it´s empty.

    What should I do? I´m trying to sniffer my network with wireshark to see the difference between browsers, but I failed =)

    Cheers,
    André Vendramini

  257. Herdiansah September 4, 2010 01:11

    Hi Jozef,

    Thanks for this class, anyway I have add a disconnect method and logoutURI variabel to this class. logoutURI is just a blank html file you can name it logout.html or something else.

    public function disconnect():void
    {
    var urlReq:URLRequest = new URLRequest(“https://www.facebook.com/logout.php?next=”+logoutURI+”&access_token=”+savedSession.data.token);
    navigateToURL (urlReq, “_logout”);

    savedSession.clear();
    protected::_token = “”;
    protected::_authorized = false;

    }

    rather than opening the logout in a new window I’m opening the logout url in an iframe named _logout, this iframe size is just 1×1 pixel.
    So once you call this method a token in shared object will be clear and Facebook login session will be clear too.

    I hope this helps.

    Cheers.

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

  259. Vincent September 6, 2010 19:03

    Hi Jozef,

    Thanks for your useful example. Works fine for me.

    I have a question. I want the users to have a cool navigation inside my flex project, so for that, your cool flex iframe is fine, non popup.

    But when i try your example on your website, here: http://blog.yoz.sk/2010/01/elegant-facebook-login-for-desktop-application/

    The login page doesn’t appear.

    Is it normal? I try for me on a simple example and same problem.

    Is it possible to add flex iframe with FacebookOAuthGraph class ?

    Thanks by advance

  260. Jozef Chúťka September 9, 2010 10:14

    Hi @André,
    how does callback url looks like in ie6? all you need is to grab the token part from it. does javascript execution goes inside the IF statement? Would advanced callback ( http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/ ) help you?

  261. Jozef Chúťka September 9, 2010 10:16

    Hi @Herdiansah, thanx for your logout method, briliant idea!

  262. Jozef Chúťka September 9, 2010 10:20

    Hi @Vincent, I am sorry to tell you that whole facebook does not work in an iframes anymore. It is a security thing for avoiding clickjacking (my best guess)

  263. PVieira September 9, 2010 16:06

    Hi Josef, another question for you. From your example i was able to load profile image from the current user directly from a loader:

    if (event.rawData is ByteArray) {
    var loader:Loader = new Loader();
    loader.loadBytes(event.rawData as ByteArray);
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
    function():void {
    image.addChild(loader);

    How can i save the picture url?

  264. Jozef Chúťka September 9, 2010 16:18

    @PVieira picture url is static “me/picture” for current user, “{user}/picture” for any other user. I suppose you want to save picture bytes (image)… hm… I guess it will not be possible directly (you do not have crossdomain.xml access) and you will need to use server side proxy to download the image

  265. André Vendramini September 9, 2010 22:58

    Hi @Jozef,

    Now I´m getting the token. But IE6 bring me a surprise: when I call https://graph.facebook.com/me it return a JSON, all right? I´ve this code to test it:

    var urlLoader : URLLoader = new URLLoader(new URLRequest(“https://graph.facebook.com/me?access_token=127580417282038|2.4FbkD2wBWPW1rwOpLrjV4A__.3600.1284066000-100000986825308|SN5oxfcEmwevG9r1nNg2es7G3UA”));
    urlLoader.addEventListener(Event.COMPLETE, test);

    function test(e : Event) : void
    {
    _txt.text = urlLoader.data;
    trace(urlLoader.data);
    }

    IE6 give me this error:
    Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL

    All browsers are working this test. It´s very simple, uh? Do you know what´s happening?

    Thanks,
    André Vendramini

  266. Jozef Chúťka September 10, 2010 10:41

    Hi Andre, please go through the article again read section “This example app works with Internet Explorer, but my one results in Error #2032″ + comments here containing string “2032”

  267. PVieira September 10, 2010 18:20

    Hi again Josef.

    I’m trying to load the picture from uid but i’m allways receiving this error:
    Error opening URL ‘https://graph.facebook.com/{uid}/picture?access%5Ftoken=null’

    The call:
    call({uid} + “/picture”, true);

    Any ideia what the problem is?

  268. PVieira September 10, 2010 18:57

    Only works with “me/picture” call, with “{uid}/picture” gives me an error..

  269. Vincent September 11, 2010 07:45

    Hi Jozef,

    Did you manage to get worked this beautiful class and your great stuff with flex iframe?

    Regards

  270. Sandi September 13, 2010 07:00

    Hello!

    Thank you for making this class.

    I am having troubles implementing it.

    It works most of the time, but sometime it does not, for no reason at all.

    Is there any limit, how many posts you can make?

  271. Jozef Chúťka September 13, 2010 09:16
  272. Jozef Chúťka September 13, 2010 09:18

    Hi Vincent, facebook managed to block its content within iframe, if you try to load facebook inside any frame/iframe, the content will be hidden or “disabled”, its because of clickjacking attacks (my best guess)

  273. Jozef Chúťka September 13, 2010 09:24

    Hi Sandi, in case of fails, what is the server response content? Or does it throw flash player exception? Facebook API has limits but it raises with your fan base (user count), I personaly never hit one… If you are not about to crawl the whole facebook database I believe you can not hit limits.

  274. PVieira September 13, 2010 11:57

    Josef, i have a little problem with swfobject parameters. The parameter id is being used by another api.

    What do i need to change in your code to change this line:
    id: “FacebookOAuthGraphTest”

    to something like:
    {other name}: “FacebookOAuthGraphTest”

  275. PVieira September 13, 2010 12:00

    I solved the problem with picture, but only with access_token, i can’t test this localy. Well, it works.

  276. Jozef Chúťka September 14, 2010 10:27

    PVieira, you can change “FacebookOAuthGraphTest” to anything… both id and name are required keys for flash attributes (used with ExternalInterface)

  277. PVieira September 14, 2010 12:42

    I will try to change the parameters, thanks.

    Now i have found another problem. I can’t connect with IE.

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

    private function facebookConnected(e:FacebookOAuthGraphEvent) {
    // doesn’t reach this
    }

  278. PVieira September 14, 2010 13:23

    I think the problem is this line that i don’t understand:
    var session:Object = JSON.decode(parameters.session);

    Any ideia what might be?

  279. PVieira September 14, 2010 17:05
  280. PVieira September 14, 2010 19:50

    Josef, you said to me:
    “PVieira, you can change “FacebookOAuthGraphTest” to anything… both id and name are required keys for flash attributes (used with ExternalInterface)”

    I don’t want to change FacebookOAuthGraphTest, i just don’t want to use id for that. That required key is being used from other api. My question is, this id is being used by your code where exactly?

  281. Jozef Chúťka September 15, 2010 09:40

    id/name is used in FacebookOAuthGraph class in connect() method … this method injects javascript method into html that later calls flash based on your id/name

  282. Herd September 15, 2010 11:44

    Hi Jozef,

    I have a few question:
    – if the user close the facebook login / cancel login, can we detect using FacebookOAuthGraphEvent.UNAUTHORIZED ?
    – and if fail to load picture can we detect using FacebookOAuthGraphEvent.ERROR ?

    Thanks,
    Herd

  283. PVieira September 15, 2010 11:50

    Thanks, i will try to change that.

  284. Jozef Chúťka September 15, 2010 16:09

    Herd,
    if user clicks “dont allow” button, the facebook makes following request:
    GET /examples/FacebookOAuthGraph/callback.html?error%5Btype%5D=OAuthException&error%5Bmessage%5D=The+user+denied+your+request. HTTP/1.1
    Host: blog.yoz.sk
    … means following arguments are sent via GET:
    error[type] OAuthException
    error[message] The user denied your request.
    you can update callback javascript to pass the error into flash and handle it from there

    I am not sure now, how would graph api request fail response look like, but generaly yes, debuging fail response may help you to be able to catch it and handle it (via extending my class) to work correct way for you

  285. […] API. You have some choice to execute the call to Facebook via Actionscript (BigSpaceship Package or FacebookOAuthGraph). It’s not an official list, maybe there is other ressource for this […]

  286. verg September 21, 2010 03:42

    Any ideas on oauth via a desktop AIR application? For the purposes of a kiosk I cannot use pop-up which are standard on with the Facebook_library_with_AIRConnect_v3.4_flex.swc. I’ve been trying to connect to a facebook users page to post to their wall. Inside my air application I’m using an htmlloader making call to the facebook api and I’m having a problem with accomplishing this:

    var html:HTMLLoader= new HTMLLoader();

    var permURL:URLRequest = new URLRequest(“https://graph.facebook.com/oauth/authorize?client_id=161216207225397&redirect_uri=http://www.facebook.com/connect/login_success.html&type=user_agent&display=popup”);

    html.load(permURL);

    I get to login, I get to the basic permissions page… and after that I try for extended permissions but fail miserably. Any help would be great, and I have scoured the net to find help and most roads point back to you.

    vErGo_O

  287. Jozef Chúťka September 21, 2010 15:25
  288. […] lack of GraphAPI support in the “officialist” Facebook AS3 API.  I’ve found a number of solutions out there and see that quite a few people have gotten some work-arounds and even some […]

  289. verg September 22, 2010 22:38

    Hi again,
    Not sure what I’m doing wrong so, I decided to start at the beginning and try the example above. So I:
    1. set up a FlashBuilder Project (easy switch from Flex),
    2. grabbed the classes, created a new application copy/pasting the code above
    3. set up a facebook application
    4. swapped out the clientId
    and redirectURI(“http://s106998.gridserver.com/facebook/callback.html”) to the app and callback on my server
    5. upload everything to my server, ran it and I get the following error in a pop-up.

    here’s the url:
    https://graph.facebook.com/oauth/authorizeclient_id=null&redirect_uri=null&type=user_agent&scope=null&display=popup
    here’s the error:
    {
    “error”: {
    “type”: “OAuthException”,
    “message”: “redirect_uri isn’t an absolute URI. Check RFC 3986.”
    }
    }

    Not sure what’s up? Any Ideas? Is it because my site does not have a domain name or something?

  290. Jozef Chúťka September 23, 2010 09:49

    Hi @verg,
    you see, there is a lot of null parameters in your url, you have to fix that first

  291. verg September 24, 2010 01:38

    wow… noobed-it on that one!! Had all those nulls in my url cuz I didn’t init() on creationComplete which sets all the facebook vars… duh! sorry. :(

  292. thanhbv September 24, 2010 20:49
  293. tom September 25, 2010 22:12

    does anybody now of an example Flash (.fla) file?
    i would love to let people post a created painting from a Flash site to their Facebook feed or photo album.
    thanks!

  294. Eric September 26, 2010 10:39

    Hey

    I cant seem to get the JS bridge to work. It looks like Facebook is passing back the # parameters to the callback html, but then flash never gets notified. Do you have a zip of all these source files somewhere for download?

    Many thanks,
    Eric

  295. Jozef Chúťka September 27, 2010 09:36

    @tom sory I have no .fla file, but library will work for flash cs compilator

    @Eric, Hi all files necessary are in the article, do you mean that your callback.html does not work for you? what is your browser/os? can you debug javascript or actionscript and see where the process fails? try read some comments for this post, there are some issues mentioned…

  296. Beans September 27, 2010 19:49

    Jozef – In regards to the flash IDE side of things, and pop up blockers – i have some information that might be of use to you, and others.

    Safari on Mac (wrongly) ignored the ExternalInterface call to open a new window. Its a well documented bug, and avoidable by using the navigateToURL function. The only problem is you need to know if you are using safari or not, or else just open the window with the external interface (blank) and then target it with the navigateToURL(urlRequestVar, ‘myWinName’).

    You could have some js in your page to be called with an externalInterface.call , but keeping with the closed style of you facebook class – i suggest you add in the following (not foolproof but its better than nothing)

    var safariJS:String = ”
    + “var browser = window.navigator.userAgent;”
    + “if (browser.indexOf(‘Safari’) > -1){”
    + ‘ return true;’
    + ‘}else{‘
    + ‘ return false;’
    + ‘};’
    + ‘window.open(“‘ + url + ‘”, “‘ + name + ‘”, “‘ + props + ‘”);’

    var id:String = ExternalInterface.objectID;
    var url:String = authorizationURL;
    var name:String = jsWindowName;
    var props:String = “width=670,height=370″;
    var urlRequest:URLRequest = new URLRequest(url);

    if(ExternalInterface.call(“function(){” + safariJS + “}”)){

    navigateToURL(urlRequest, “_blank”);

    }else{

    var js:String = ”
    + ‘if(!window.’ + jsConfirm + ‘){‘
    + ‘ window.’ + jsConfirm + ‘ = function(hash){‘
    + ‘ var flash = document.getElementById(“‘ + id + ‘”);’
    + ‘ flash.’ + jsConfirm + ‘(hash);’
    + ‘ }’
    + ‘};’
    + ‘window.open(“‘ + url + ‘”, “‘ + name + ‘”, “‘ + props + ‘”);’

    ExternalInterface.call(“function(){” + js + “}”);

    }

    As a side note to this, its worth noting that these have to be triggered by a method that captures a mouse event.If for example, the function is triggered on the result of a data call – think zendAMF or a an image load (basically something that requires time to process) the external interface call will fail silently. In this case you would need a prompt to continue.

    The second problem that you face with Safari on OSX deals with the problem of callbacks from another window. It seems that safari does not keep the relationship of parent/child – and window.opener will always == null. I have tried in vain to fix this with js, but im not very experienced that way. I tackled the problem a little differently (to save space i will describe it here, if anyone wants the code just comment back)

    basically i rig up a callback.swf that has a list of all the callbacks i want to use on my site. I embed this on the callback.html page. When the swf loads, it uses the external interface to check a dummy js function to make sure javascript is ready. If it is false, a timer is set up to ping the js. Once javascript ready condition == true, i external interface call another js function that returns the method name i want to use as my callback.
    In flash i have a localConnection set up with the main flash app, and my callback swf. The callback.swf has the method name, and then performs the method (with any arguments) across the local connection.

    So far it has been a rather nice solution to a frustrating problem that only safari osx seems to suffer from. And finally – thank you for the great code. It has helped me flesh out my flash app very n icely.

  297. […] the GraphAPI.  Hopefully we’ll be able to integrate ideas.  As well as the steps that Josef has taken to getting the OpenGraph into the AS3 world and Toby’s return to the JavaScript bridge. […]

  298. Jozef Chúťka September 28, 2010 10:14

    Hi @Beans, thank you for your instructions and solution. I have added it into FAQ section, I think this is really useful to know, I never used this class on mac-safari config by myself.
    Did you tried my advanced callback “Advanced Crossdomain Working Authorization” on:
    http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/

  299. Herdiansah September 29, 2010 16:09

    Hi Jozef,

    Is there anyway to opening the facebook login in an iframe rather than opening in a popup window?

    Thanks,
    Herdiansah

  300. Jozef Chúťka September 29, 2010 17:48

    Hi @Herdiansah,
    it is not possible, facebook blocks its content within iframe, you can make simple test… I guess due to clickjacking it is

  301. Cechise September 30, 2010 19:59

    THANK YOU!

    Excellent class. Very nice work.

    I’m using it in one of my projects now and it works like a charm.

    I was thinking about making a popup-confirmation when posting to wall like the one you get from the fb javascript sdk. So i’m trying to do this in the same way you did the authorization window, but haven’t quite gotten it to work.

    Have you done this or do you have any thought if its possible?

  302. Siret September 30, 2010 23:19

    hi! i would like to use the FLEX example from above in FLASH.
    what do i need to change? please help! :)

  303. Jozef Chúťka October 1, 2010 09:44

    Hi @Cechise,
    1. you are using flash, you have free hands to do any UI you want with your custom graphics etc. or
    2. you can use javascript sdk or
    3. you can sharer.php in popup – http://www.facebook.com/share/

  304. Jozef Chúťka October 1, 2010 09:46

    @Siret,
    all you have to do is change the main class in terms of to use your own custom UI (maybe http://www.minimalcomps.com/ ), all libriaries should work for CS compiler

  305. Siret October 1, 2010 18:13

    i don’t get it to work in FLASH. are there any code or file downloads available please?
    thanks

  306. Ilya October 1, 2010 22:36

    Hi,

    I am using your class on my site and it works great.

    Now I am sending flash post to my users wall, and I want to add there a share button, just like in my site, that will register them to the application and make a post on they wall.

    But I can’t do it now, because I have no control on Facebook html file where my swf file is loaded.

    Is there any way to this?

  307. Jozef Chúťka October 4, 2010 11:31

    @Siret, I have uploaded working .fla, please read FAQ … download link there.

    Hi @Ilya, graph api does not contain like function, you have to generate it via facebook iframe widget… after user likes your application, he can publish feeds into your application/page feed stream

  308. Porter October 4, 2010 23:15

    something seems to be wrong with your HTML part.
    the .swf don’t show up!!

    CODE: http://pastebin.com/VwMi4knS

    it’s always just the alternative content that gets displayed.
    what’s wrong it?

  309. Jozef Chúťka October 4, 2010 23:20

    @Porter, it seems like you are having issue with javascript, is your swfobject.js file located correctly?

  310. Porter October 5, 2010 01:04

    yes it’s in the same folder. (swfobject 2.2)
    anybody experienced the same problem? WindowsXP with IE / Firefox / Chrome / Opera

  311. Jozef Chúťka October 5, 2010 11:55

    @Porter, its definitely a javascript issue, make sure your javascript is correct… I can see undefined variable flashvars etc… use firebug to debug javascript

  312. Donny October 13, 2010 06:40

    what a great tutorial,, :cheers:
    Hi,,,
    noob here,, n i got the same problem with Ilya,,
    can u make an example about it?? or you have some?

    thanx a lot :D

  313. Jozef Chúťka October 13, 2010 10:04

    Donny I am not sure if I am getting this correctly, are you trying to be able to connect to facebook via flash feed post? like when running youtube video from feed and somewhere inside this flash a button to connect? yes it is possible, however, you can not use javascript popup but navigateToURL() into new window, than use advances callback, so user gets access_token via NetConnection (advanced callback http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/ )

  314. david October 14, 2010 01:08

    hello Jozef

    If i’m already logged-in facebook, and i trigger the connect method, i have the fb_callback popup that pop and then auto close.

    i there a way to avoid this window to pop when i’m already connected ?

    Thank you

  315. Jozef Chúťka October 14, 2010 10:17

    Hi david,
    why do you let your script call connect when you are connected already? use FacebookOAuthGraph.authorized to show/hide connect button etc.

  316. david October 14, 2010 22:10

    hummm FacebookOAuthGraph.authorized return false if i don’t connect before.

    Do i need to use the autoConnect ? (but with what parameters ? )
    verifyToken? ( same, don’t know my token)

    i’m a bit confused.

  317. Jozef Chúťka October 15, 2010 10:52

    @david, yes you should use autoConnect() inside init() (see line 33), it works with 2 sources:
    1. stage.root.loaderInfo.parameters (if you pass access_token via flashvars, used with iframed facebook app http://blog.yoz.sk/2010/06/authorizing-iframe-facebook-applications-for-graph-api/ )
    2. ShaderObject data – previous working token is autmaticaly stored and used by autoConnect()
    … you may want to require “offline_access” extended permissions so your stored tokens are valid for a long time

  318. david October 15, 2010 23:13

    ok, it was the shared object that was missing me…

    i’ll test it..

    thank you

  319. Kirk Elliott October 19, 2010 21:25

    Any way to make this retrieve the contents of a fan page’s photo album? I mean the user posted images to the fan page, not the official fan page photos. A lot of people would use this if you could make it happen.

    Great work!

  320. Bill Langley October 19, 2010 23:20

    Hi Jozef,

    Hey, I just found out (the hard way) that session parameters are now coming in escaped on an app I built. It was a simple fix:

    public function autoConnect(parameters:Object=null):URLLoader
    {
    if(parameters && parameters.hasOwnProperty(“session”))
    {
    var session:Object = JSON.decode(unescape(parameters.session));
    if(session.access_token)
    return verifyToken(session.access_token);
    }

    return verifySavedToken();
    }

    but I wasn’t sure if this was something FaceBook changed or in my client’s environment.

    What do you think?
    WL

  321. Jozef Chúťka October 20, 2010 10:13

    Hi Bill,
    thanks for your code, I suggest you do it using the “override” way ( http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/ ), I am just checking my session parameter and it seems like it is encoded correctly as it should be – once, when value passed into flashvars (via javascript), the variable parameters should containt decoded – raw value… but if that was an issue in your case I am glad that you made it work…
    Anyway I recommend to use charles proxy – great tool for debugging this kind of things (requests/responses/data etc.)

  322. Jozef Chúťka October 20, 2010 10:17

    @Kirk, you can post images directly into page album, and you can also grap photos from this album or from an album of any user if correct permission granted (user_photos) … later it is no problem to get album content via https://graph.facebook.com/ALBUMID

  323. jiannis October 21, 2010 17:02

    I have the same problem like : markval (on June 22, 2010 | 01:11)
    and can’t seem to be able to override it, although I use a SecurityError Listener. I push all the rawData (of the user’s friends) in an array and then load them serially.
    If an avatar picture is missing none of the avatars is loaded – got a clue why?

    call(id+”/picture”)

    private function call (path : String, binary : Boolean ) : void
    {
    friendLoader = new URLLoader();

    friendLoader = facebook.call(path);
    friendLoader.dataFormat = binary ? URLLoaderDataFormat.BINARY : URLLoaderDataFormat.TEXT;

    friendLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
    friendLoader.addEventListener(FacebookOAuthGraphEvent.DATA, onCallComplete);

    }

    private function securityErrorHandler ( e : SecurityErrorEvent ) : void
    {
    trace(“ERROR ERROR SECURITY BREACH OUWAOWA: ” + e);
    }

    private function onCallComplete ( e : FacebookOAuthGraphEvent ) : void
    {
    if(e.rawData is ByteArray){
    rawDataURL.push(e.rawData);
    counter++
    }
    else{
    for (var i : int = 0; i < e.data.data.length; i++ ){
    friendId.push(e.data.data[i].id);
    friendName.push(e.data.data[i].name);
    }
    }
    }

    THANKS!

  324. Jozef Chúťka October 21, 2010 17:46

    @jiannis, do you use debug player? what is the Exception being thrown?

  325. jiannis October 22, 2010 10:58

    @jozef, i get the following error in the firebug flash tracer:
    rRror: Request for resource at http://b.static.ak.fbcdn.net/rsrc.php/zo/r/UlIqmHJn-SK.gif by requestor from http://changemod.com/facebookAPI/graphApi/FacebookGraphApi04.swf is denied due to lack of policy file permissions.

    The debugger doesn’t throw any error.

    I also get a trace from the SecurityErrorEvent:

    Error #2048: Security sandbox violation: http://changemod.com/facebookAPI/graphApi/FacebookGraphApi04.swf cannot load data from http://b.static.ak.fbcdn.net/rsrc.php/zo/r/UlIqmHJn-SK.gif.”

    any clues?
    thanks in advance!

  326. Ciaran October 23, 2010 02:08

    Hi Jozef,

    Ive tested your flash CS4 source files and cant seem to connect? After you click the app freezes on “connecting…”? Any ideas why?

    Thanks

    C

  327. Ciaran October 23, 2010 18:57

    Nevermind got it working now :)

    Thanks for posting this article, really helped me out!

    C

  328. Jozef Chúťka October 25, 2010 09:55

    @jiannis, in order to access raw data (bytes) from http://b.static.ak.fbcdn.net/rsrc.php/zo/r/UlIqmHJn-SK.gif , you need to download crossdomain.xml from b.static.ak.fbcdn.net domain

  329. Jozef Chúťka October 25, 2010 10:02

    @Ciaran, cool, maybe you could send info what was the issue (I guess just some mistake in process), it may help some other developers too

  330. jiannis October 25, 2010 11:03

    @jozef, thanks I tried that but I think b.static.ak.fbcdn.net/crossdomain.xml doesn’t allow access from just any domain.

    Is there a way to check the URL of the request before it tries to load the image? Then I could replace the images coming from b.static.ak.fbcdn.net with an image saved locally.

    thanks a lot!!

  331. Jozef Chúťka October 25, 2010 12:36

    @jiannis, if there is not suitable crossdomain, in general you should/can:
    1. do not access raw data, use Loader.load() in order to just display image
    2. use proxy to access data

  332. jiannis October 25, 2010 14:01

    @jozef, got it! thanks a million!

  333. Soleh Ayubi October 26, 2010 15:09

    I’ve developed an apps in facebook.
    Three weeks ago, it worked perfectly but since 2 days ago, it goes wrong. It is always loading and refreshing over and over again.
    Here is my code to connect to facebook:
    public function loginToFacebook():void
    {
    _flexVar = Application.application.loaderInfo.parameters;
    facebookSession=new FacebookSessionUtil(_flexVar.fb_sig_api_key, null, Application.application.loaderInfo);

    And these are the errors that I got, actually it’s not error message but address of web the facebook loading and refreshing over and over again.
    Please help me.

  334. Jozef Chúťka October 26, 2010 17:46

    Soleh Ayubi, it seems like you are not using FacebookOAuthGraph library but the official Adobe one, please ask the question on their discussion forum

  335. PVieira October 26, 2010 18:04

    How can i get wall photos?

  336. Jozef Chúťka October 28, 2010 10:04

    @PVieira me/feed to get feeds on wall, then iterate and get those with image attachments

  337. Renan Joker Amaral October 28, 2010 22:16

    Guys, did any one tried to use this API after facebook changed its security protocols in 10/12 ?

    I’m getting this response to my post wall (function publishPost):
    “Failed to load source” for: https://api.facebook.com/method/stream.publish

    I might screwed something (always possible) but after some digging, I haven’t found anything about this, and since this security changes is recent, I’m wandering…

  338. Jozef Chúťka November 1, 2010 12:26

    @Renan, stream.publish (part of old REST API http://developers.facebook.com/docs/reference/rest/stream.publish ) works just fine … could you paste here the full exception text+code? do you use secured or unsecured path? do you host your app on secured or unsecured domain?

  339. […] Facebook AS3 Graph API 的作法,請參照 Jozef Chúťka 前輩所寫的 Facebook Graph API & OAuth 2.0 & Flash (update) […]

  340. robrob November 9, 2010 18:47

    Hi Jozef,

    after a while during which I did not touch my app, I today tried to publish to a user’s stream. Therefore I integrated your Code from the FAQ Section

    var media:Object = {};
    […]
    facebook.call(“method/stream.publish”, data, URLRequestMethod.POST, null, “https://api.facebook.com”);

    Unfortunately this doesn’t do the trick inside my app / my configuration.

    Background:
    – My App is generally able to connect with facebook and execute calls like the following
    facebook.call(“method/fql.query”, data, URLRequestMethod.POST, null, “https://api.facebook.com”);
    – But, my config is incomplete aka faulty, that is why I have to fetch a access-Token by hand, when I want to run the app outside of facebook. And, what baffles my most: When I add permissions (like create_event, manage_pages) the app aka facebook still does not asks me for allowance.

    Any help would be great,
    Thx, Robson

  341. Jozef Chúťka November 10, 2010 13:28

    Hi robrob,
    I guess https://api.facebook.com/method/stream.publish does not for you is what are you asking me to help you with? Can you debug/trace the response from facebook on your call. Than we can move forward to investigate this

  342. robrob November 11, 2010 00:18

    Hi Jozef,

    thanks for your response. The error message confirmed the assumption, that the problem results out of insufficient permissons. So I’ve got some more study to do.

    I appreciate all your quality stuff. Big thx,
    robrob

  343. Jozef Chúťka November 11, 2010 19:14

    robrob, you are welcome

  344. robrob November 11, 2010 21:58

    Hi Jozef,

    I am making progress, but still have some questions.

    1. Is it correct, that opening the pop-up inside Facebook can only be executed, if it is triggered by the user clicking. Because right now it does work local, but not on FB. I thought I read something similar on here, but can’t find it anymore.
    2. Is it correct, that the External Interface call isn’t handled by safari browsers.

    Can’t thank you enough.
    On that note: Where is your donate button?
    robrob

  345. robrob November 12, 2010 03:43

    Hi again,

    as there is a clear statement to the second question of my previous comment, I would like to restate my post as follows ;)

    ————————————
    Hi Jozef,

    I am making progress, but still have some rookie questions.

    1. Am I assuming correct, that if everything is setup correctly, the user has to give permission only once and afterwards permission will be given automatically, without any need of user-action?
    2. Is it correct, that opening the pop-up inside Facebook can only be executed, if it is triggered by the user clicking? I am asking, because I added an event-listener for FacebookOAuthGraphEvent.Error and tried to launch the External-Interface automatically if the user hasn’t authorized the app yet. This works local, but not on FB. (I thought I read something similar on here, but can’t find it anymore).

    Still can’t thank you enough.
    And again: Where is your donate button?
    robrob

  346. Sven Forshell November 12, 2010 12:39

    Hi jozef!

    Do you know what other values that these can be sent with a photo upload? For instance, I don’t want to publish this photo in my feed, how do I go about it?

    var values:Object = {
    message:’My Caption’,
    fileName:’FILE_NAME’,
    image:img
    };
    Facebook.api(‘/me/photos’, handleUploadComplete, values, ‘POST’);

  347. Jozef Chúťka November 12, 2010 15:44

    Hi robrob,
    thank you for the donation button suggestion, I have added a donation button into http://blog.yoz.sk/facebookoauthgraph/ section “Donations”

    You may want to open popup without user interaction, there is no restriction within my library. What restricts your pop-up to be open is popup blocker (browser plugin or browser native behaviour), you may try to open new window via navigateToURL but based on browser blocker this action may also be prohibited from being called without user interaction.

    If your user connects with your application, he receives token valid like 30 minutes (I guess), this token is saved into SharedObject that persists on his pc. Next time he comes into your app, the lib first try to use the stored token if it succeed you are connected else he have to click connect again. In order to make the token valid for long period of time (unlimited) request “offline_access” permission with scope parameter.

    There are more safari users complaining about some javascript behaviour, please go through the blog comments here to find the solution. If you dont find any, try asking again, I am not sure I understood the issue

  348. Jozef Chúťka November 12, 2010 15:54

    Hi Sven,
    check out this article about uploading a photo vs. publishing post with image:
    http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/ … sections “Uploading Photo” and “Publishing Feeds”

  349. robrob November 12, 2010 17:53

    Hi Jozef,

    sure thing, I am happy to give something back.

    So, do I get it right, that
    1. The user has to click a button every once in a while, to let the app establish a connection to Facebook?
    Except if I ask for offline access permission, which itself gives not 100% guarantee, because the shared object can get lost if a user shout his Pc?

    2. If a user logs in, logs out and logs in with a different account, he will be treated as the first user, unless I implement some logout logic, which flushes the shared object?

    3. Would any of this be different, if I would follow your authorizing with IFrame-Article? (http://blog.yoz.sk/2010/06/authorizing-iframe-facebook-applications-for-graph-api/)

    Many Thanks,
    robrob

  350. Jozef Chúťka November 12, 2010 18:59

    @robrob,
    paypal notification already received, thanks again ;)

    1. exactly. But if user keeps communication with his token on graph api he will not get unconnected anyway. I guess offline_access gives you good guarantee, I did not tried it any longer but it lasts more than a month for sure. Docs says:

    “offline_access Enables your application to perform authorized requests on behalf of the user at any time. By default, most access tokens expire after a short time period to ensure applications only make requests on behalf of the user when the are actively using the application. This permission makes the access token returned by our OAuth endpoint long-lived.”
    http://developers.facebook.com/docs/authentication/permissions

    2. right. he is identified by stored token. you can make logout function as easy as described here http://blog.yoz.sk/2010/05/facebook-graph-api-and-oauth-2-and-flash/#comment-2001
    it should be able to compare these users by /me vs. /me?token

    3. everything mentioned here remains the same for iframe version, its more less the same in all aspects

  351. shammi November 16, 2010 16:08

    var js:String = ”
    + ‘if(!window.’ + jsConfirm + ‘){‘
    + ‘ window.’ + jsConfirm + ‘ = function(hash){‘
    + ‘ var flash = document.getElementById(“‘ + id + ‘”);’

    hi i am unable to know what i need to put in place of id. also i am not able to get the access_token. i don’t know why. i do not see any code in java script which will call jsConfirm inside flash do i need to provide the id for flash object in your FacebookOAuthGraph.as class?

    i am making in in flash Professional and html page has javascript.

    if u can explain it would be great. after i log on to facebook what happens how does your code get the access_token after i see the message ” You may now close this window.” thanks for you help

  352. Jozef Chúťka November 16, 2010 17:25

    hi shammi,
    yes you need to specify id and name for your flash object in html:
    var attributes = {id: “flash”, name: “flash”}; // or “whatever”, need same values for id and name
    swfobject.embedSWF(“…swf”, “alternative”, “100%”, “100%”, “10.0.0”,
    “flash/expressInstall.swf”, flashvars, params, attributes);

    than, there is no need for changing the code in .as file, ExternalInterface.objectID contains the value of whatever you put inside swfobject attributes.id (.name) …
    read the part of article starting with sentence “Make sure your html wrapper defines correct allowScriptAccess”.

    Popup window should close itself when it is able to find your main flash and it also passes token into it via javascript/ExternalInterface

  353. magicDamo November 16, 2010 21:22

    Hi Jozef,
    Thanks for the article.
    I am using the GraphAPI and a canvas based application.
    I would like to get a list of my friends who are using ‘this app’. is there a way to do this with the GraphAPI?

    thanks

  354. Don November 17, 2010 09:20

    When I call me/feed it doesnt return anything?

  355. shammi November 17, 2010 13:20

    hello jozef
    if the window “You may now close this window” does not close on it’s own. is it a cross domain issue. actually instead of adding the callback.html file to a domain i called http://blog.yoz.sk/examples/FacebookOAuthGraph/callback.html for redirect url. and also i use your client id. i wanted to check if your code can be converted to a flash application. i am still unable to understand what this line of code does.
    var js:String = ”
    + ‘if(!window.’ + jsConfirm + ‘){‘
    + ‘ window.’ + jsConfirm + ‘
    ——
    jsConfirm =”confirmFacebookConnection”
    callback.html page does not close on it’s own so i do not what to do?

  356. Jozef Chúťka November 17, 2010 13:51

    Hi magicDamo, you have to use rest api call with FQL:
    http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/ see section “Application Friends”

  357. Jozef Chúťka November 17, 2010 13:52

    @Don, it is a standard http request, it must return something even if it was an error code. please debug and trace the response

  358. Jozef Chúťka November 17, 2010 13:59

    hi shammi, yes, it keeps opened if it is a crossdomain issue or it can not find confirmFacebookConnection() function in wrapping html javascript. this is the javascript function being injected by actionscript in the time when your popup is opened… those are exactl the lines you are asking about. you can not connect with my callback due to XSS. Read about “Advanced Crossdomain Working Authorization” here http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/

  359. Don November 17, 2010 14:45

    Sorry Jozef it returns blank data
    {
    “data”: [

    ]
    }

  360. Jozef Chúťka November 17, 2010 14:57

    Don, go to http://developers.facebook.com/docs/api and click me/feed link there. does that contain your data? if so you are missing some permissions with application, if not you somehow blocked your wall content in facebook settings for your account

  361. Matt F November 18, 2010 14:28

    hi all,

    first of all, thanks jozef for a fantastic couple of classes, they’re going to really save my bacon!

    but… I’m having problems getting the AUTHORIZED callback to function at all. Code is set up virtually identical to yours and the app knows whether its connect or not (the facebook.authorized var is set to true when you would expect it) but the callback just does not seem to be called at all. I’m utterly mystified!

  362. Jozef Chúťka November 18, 2010 16:17

    Hi Matt,
    go through article on http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/ up to the section “Auto Execution After Authorization”… does this attemp fix your issue?

  363. Ellis November 19, 2010 04:53

    hi Jozef

    really thank you for the source!!^_^

    but i have a question

    can i get the (UserLoginState) before (publish.stream) methods?

    prevent from the situation when user logout manually

    thank you very much

  364. Jozef Chúťka November 19, 2010 19:01

    hi Ellis, you can call “/me” to get info about logged user

  365. Don November 20, 2010 12:13

    Thanks Jozef, very cool what you have done here!

  366. Don November 21, 2010 15:45

    Sorted my problem with the me/feed with read_stream permission.

  367. Carlos Monzon November 24, 2010 16:58

    Hi Jozef i am a Flex 3 Developer i found this api to connect to facebook and looks great! xD
    But… i’ve 2 days trying to make this api works in IE8 and… nothing…
    I saw your app in http://apps.facebook.com/blogoauthgraph/ and test it in IE8 and works perfectly then try my app and doesnt works in IE8…
    My app is http://apps.facebook.com/fbookauth/
    Please if you now how to fix this.. help me..
    thank you very much.

  368. Jozef Chúťka November 24, 2010 17:20

    Hi Carlos,
    your app works for my IE8. make sure to clear your cache and try it again…
    what exactly means “doesnt works in IE8″ does it fall in endless redirect loop?

  369. Carlos Monzon November 24, 2010 17:58

    Hi Jozef thanks for your answer…
    My app dont falls in endless redirect loop, i try to clear cache and temporary files and still dont work.
    The problem occurs when i try to login… in the left panel shows checkSavedToken(), then shows connect() and never shows the label “authorized”… i try my app in IE7 and IE8 and never shows this label in FF,Chrome, and Safari works great!
    I’ve debugin the class FacebookOAuthGraph.as and I found the function called “verifyToken”.. in this function never execute the code:

    loader.addEventListener(FacebookOAuthGraphEvent.DATA,
    function(event:FacebookOAuthGraphEvent):void
    {
    EventDispatcher(event.currentTarget)
    .removeEventListener(event.type, arguments.callee);
    verifyTokenSuccess(event, token);
    });

    then… the verifyTokenSuccess never called…
    I put a Alert.show(token); at begining and now in the application shows the “178299352184385|2.7rMLm_8DQxDlCd8oyRApwA__.86400.1290700800-737101097|Z2uIg0gi8-Uk2ljvXmscFmEHRVI” …
    But… still doesnt work and the token is not null…

    Thank you very much for the help…

  370. Jozef Chúťka November 25, 2010 15:41

    Carlos, may this be your issue?
    http://blog.yoz.sk/2010/05/facebook-graph-api-and-oauth-2-and-flash/comment-page-8/#comment-2509
    follow a few comments below to see… if not than try searching verifyToken in this page

  371. […] Facebook AS3 Connect 方法在此一樣不提,請自行參考教學連結。 […]

  372. Carlos Monzon December 3, 2010 19:50

    Hi Jozef, thank you for the help…. I’m still working in this problem, now i debug the application again and found in the FacebookOAuthGraphEvent.as class the variable _rawData and this var get the value “Error #2032″ only in W7 with IE7 and IE8, i was searching this issue about 3 days and i can’t fix this… i tried the headers solution putting application/json, building the application for flash 10, and… nothing, if you know something about this error please help me..
    Thanks for the help…

  373. Edwin December 4, 2010 22:00

    Hi, Thanks for this great class. It helped me alot!

    I’ve spent days trying to make this work across all browsers and I’m having a weird problem now.

    Here’s the error:

    Error: Permission denied for to get property Window.confirmFacebookConnection from .

    This error only comes up in firefox and everything works in IE/Chrome/Safari on both Mac and PC.

    Another problem I’m having is getting it to open in a small window instead of a big window. i.e. to say, using super.connect() instead of navigateToURL doesn’t work.

    I would really appreciate if I can get some help! Thanks!

  374. Edwin December 4, 2010 22:15

    Turns out that in the end, the prefix www is the problem after all!

    If you’re loading the website without a prefix of www, and your redirect URI is one with a prefix of www, it will throw you an error.

    After spending HOURS trying to figure out what went wrong, this WAS IT! Hopefully someone will benefit from this. :)

    Btw, here’s a snippet to detect the domain of where the swf is loaded so that you can load the correct redirect URI.

    var urlPattern:RegExp = new RegExp(“http://(www|).*?\.(com|org|net)”,”i”);
    var found:Object = urlPattern.exec(root.loaderInfo.url);
    var redirectURI:String = found[0]+”/advancedcallback.html”;

    found[0] will basically return you something like “http://domain.com” or “http://www.domain.com”

  375. Jozef Chúťka December 6, 2010 15:54

    Carlos, the bug is reported on facebook bugzilla fir more than 6 month now, no solution / feedback from dev team
    http://bugs.developers.facebook.net/show_bug.cgi?id=10631

  376. Jozef Chúťka December 6, 2010 16:00

    Hi Edwin, yes, be careful with crossdomains… read more about flash security on
    http://kb2.adobe.com/cps/142/tn_14213.html
    http://www.senocular.com/flash/tutorials/contentdomains/
    http://www.senocular.com/pub/adobe/crossdomain/policyfiles.html

    I did not got your issue with openning small window … it is bone by default

  377. Edwin December 6, 2010 17:13

    @Jozef, thanks for your reply. The small window problem was a mistake on my part. :) Thanks for sharing this great solution too!

  378. kalel December 11, 2010 18:31

    Hi, great stuff! I am currently using your classes in creating a simple app. One question though, how do i trigger the pop-up dialog that asks users to post a message to their walls when a button is clicked inside the flash app? Thanks!

  379. Jozef Chúťka December 13, 2010 09:59

    Hi kalel,
    this class is not javascript api based, thus there is no popup window to be opened… you can call the publish method from inside the flash, no evil popup required. make your own graphics and form inside your flash app in order to publish comments.

  380. gilles December 20, 2010 11:04

    Hi,
    Just a small question ?
    it possible to have to use this class for a flash application dropped in fbml canvas in a fan page tab, I think we can but just a confirmation from an expert will save some time.

    anyway great work, it helps me a lot.

  381. Jozef Chúťka December 20, 2010 12:47

    Hi gilles,
    you can use this lib anywhere. If you are able to pass token into flashvars you will get connected

  382. gilles December 20, 2010 14:07

    great thanks, I’ll try. so it’s the only way left to make interactive app in a fan tab.
    thanks again

  383. gilles December 21, 2010 22:53

    Hi,

    I made fbml app with a flash inside and I have a really weird behaviour, which i think is not because of your class, I have a sandbox violation error, it doesn’t want to addCallBack to js function when i call the connect function. I have the same probleme with the official api. Thanks for helping.

  384. Jozef Chúťka December 22, 2010 11:11

    gilles, can you debug the exception? on what line does it throw this exception?

  385. gilles December 23, 2010 17:16

    hi, it comes from the connect function, but actually now facebook doesn’t allow script access to flash on fbml canvas. that’s why the sandbox doesn’t allow me to have js callback.

  386. gilles December 23, 2010 17:18

    I found a solution by ask for autorisation which go to my callback with the token dans then do what i want do with facebook by calling php script from flash which curl the facebook graph. Maybe there is a simpler way but the sandbox also block me when i call the graph url directly from flash. thanks for your help.

  387. Jozef Chúťka December 25, 2010 10:23

    gilles thankx for the response gilles, I did never worked with fbml embeding flash much. I guess it is easier to use iframe while it gives you more freedom about how do you want to embed flash and things…

  388. charles-j January 4, 2011 18:33

    Does anyone managed to publish a swf on a facebook application fan page?

    something like
    FacebookDesktop.api(‘/app/feed’, callback, attachment,’POST’);

    Basically I try to figure out how adidas managed to do it on their fan page
    here
    http://www.facebook.com/adidasoriginals?v=wall

    ??

  389. Jozef Chúťka January 5, 2011 11:16

    charles-j, you can simply do that with FacebookOAuthGraph. read http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/ section “Publish feed with flash” and comment http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/#comment-2336 for targreting feed into fan page

  390. mike w January 6, 2011 04:37

    fantastic job you’ve done here :)
    i can run your cs4 flash only version fine using your parameters supplied for callbackurl and app id, when i try to use my app id and callback html on my webserver it doesnt authenticate – i think i’ve missed something.

    can you tell me “redirectURI” is this meant to be the same value the same as the Bookmark URL in the Edit Settings section for the app on facebook config page? I got the popup and permissions request fine first time app loads but doesnt seem to go anywhere. was there anything special in facebook settings ?

    many thanks

  391. Jozef Chúťka January 6, 2011 11:31

    @mike,
    here are all the fb settings for my demo app http://blog.yoz.sk/examples/FacebookOAuthGraph/settings.png
    – Bookmark URL is not important for you at all
    – Define Site URL and Site Domain correctly for your domain in Web Site tab
    – Define redirectURI within Site Domain you defined in fb settings
    that should be all the necessary. There were some comments reporting issues with connection, we were able to fix them all. go through the comments posts here using “connect” fulltext search and I believe you will find a solution.

  392. Pipe January 18, 2011 23:52

    I Jozef,

    Thanks for your code, works great!

    I have only one question…
    There’s a way in the application to recognize te current user?

    I mean, if I load this page, click connect and “log me in” in facebook as “USER A”, all works fine.

    If i go to facebook and log out USER A, and then log in with “USER B”, then reload this page, all info is fetched from USER A (Not USER B who is currently logged in)

    There’s a way to do this?

    Thanks a lot!

  393. Jozef Chúťka January 19, 2011 10:59

    Hi Pipe,
    you can use FacebookOAuthGraph.me to read info about current api user. This value is filled once you are logged in. There is a separated authorization system in facebook for classic facebook.com vs. api. Api is token based, once you have valid tokens you can make api requests as any user not just the one that is logged on facebook.com. The token for FacebookOAuthGraph is saved in SharedObject (something like flash cookie) and is used with autoConnect(). You can logout api user as easy as remove the token from sharedobject, feel free to extend my lib with disconnect method() – search for “disconnect” in comments e.g. here:
    http://blog.yoz.sk/2010/05/facebook-graph-api-and-oauth-2-and-flash/comment-page-8/#comment-2001

  394. Donny January 27, 2011 07:40

    hey jozef,
    i try to implement your tuts about “change facebook Status” part n i’ve made it, but when i try “publishing feeds with image” part i got a problem,
    i wanna ask bout these lines

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

    n i got an error = 1120: Access of undefined property JSON.

    what should i do? coz i noob here,, :D

    thx before :cheers:

  395. Jozef Chúťka January 31, 2011 12:13

    Hi Donny,
    JSON is not a property but a class. you can import one from original adobe package
    import com.adobe.serialization.json.JSON

  396. fltz February 10, 2011 18:17

    Jozef,
    how can I upload and post an image into user’s wall? As I learned from the documentation POST to /me/feed could only publish an image by URL. But I need to upload an image from user’s desktop.
    Someone said that all I need is uploading by using /me/photos. But uploaded photo just saves into app’s album, with no sight in the feed.
    Is there workaround for this?

    Thanks

  397. Jozef Chúťka February 11, 2011 11:50

    fltz,
    I am sorry to tell you that only possible upload with graph api is to an album. What makes perfect sense because, there is also a “Wall Photos” album for your wall uploads. So to make your upload appear within your feed do:
    1. upload photo (one album will be created as default for your facebook app)
    2. publish feed linking to your upload

  398. Paul February 14, 2011 13:30

    Really useful package. But!

    You need to override the clone method in your FacebookOAuthGraphEvent class, otherwise you can’t redispatch the event (I lost some time trying to terack this down :P )

    public override function clone():Event
    {
    return new FacebookOAuthGraphEvent(type, bubbles, cancelable, _rawData);
    }

    —–

    from http://livedocs.adobe.com/flex/3/html/help.html?content=createevents_3.html

    “You are required to override the Event.clone() method in your subclass. The clone() method returns a cloned copy of the event object by setting the type property and any new properties in the clone. Typically, you define the clone() method to return an event instance created with the new operator.”

  399. Jozef Chúťka February 14, 2011 14:48

    Hi Paul,
    thank you for your feedback, one really should override clone method when extending Event… I have updated the FacebookOAuthGraphEvent file.

  400. Nim February 21, 2011 11:30

    Hi Jozef,

    Thanks for your great code!

    I just download your .fla version from (http://blog.yoz.sk/examples/FacebookOAuthGraph/src/cs4.zip) and build my own on local, I has been copy the access_token value into my code and publish. but Output error:
    “Error opening URL ‘http://graph.facebook.com/me?access%5Ftoken=268718683475%7C2%2EvEgS2u9mUeGFAcXpPj1GVw%5F%5F%2E86400%2E1298365200%2D100000285065268%7C1ZyFjXGaxrEqI505%5FA2XBeaVyrw'”

    I wonder are your .fla source is uptodate? or have any change on facebook make it not work?

    Thanks a lot!

  401. Jozef Chúťka February 22, 2011 12:59

    Nim, there are changes everyday… but, if you are trying to access data with a token, make sure its secured request – https://… !

  402. kaniskar Goodwin February 23, 2011 08:39

    Hi Jozef,

    I have face one problem, bellow mentioned function is not call,if you have any solution can u share with me

    loader.addEventListener(FacebookOAuthGraphEvent.DATA,
    function(event:FacebookOAuthGraphEvent):void
    {
    EventDispatcher(event.currentTarget)
    .removeEventListener(event.type, arguments.callee);
    verifyTokenSuccess(event, token);
    });

    Thanks a lot.

  403. Jozef Chúťka February 23, 2011 22:09

    Hi kaniskar, may this be your issue?
    http://blog.yoz.sk/2010/05/facebook-graph-api-and-oauth-2-and-flash/comment-page-8/#comment-2509
    follow a few comments below to see… if not than try searching verifyToken in this page

  404. Marco March 15, 2011 18:11

    Hi jozef. I m having a problem with authentification, is making an infinitive loop. When the app is trying to open. Its must be something that facebook api change because it was working until last week.

    The url is http://apps.facebook.com/meditubrillolux/

    ill wait your answer.

    thanks!
    marc

    p.s. sorry for my english, im from Argentina

  405. Jozef Chúťka March 16, 2011 11:11
  406. Ayubi April 9, 2011 05:39

    Hi, I have a problem with Facebook flex.
    My apps is working fine but when I put a chart (any chart, either native from flex or from outside flex) on my apps, it doesn’t show up.

    Anyone can help?

    Thanks.

  407. jiannis April 18, 2011 10:28

    for those of you still having problems with the https/ssl of facebook, there is a solution:
    the fql api of facebook has the following parameter: return_ssl_resources

    So when you do an fql query for photos, etc try this:

    //get thumbnails from ‘uid’ album
    var data:URLVariables = new URLVariables();
    data.query = “SELECT src_small” + “FROM photo ” + “WHERE aid IN ( SELECT aid FROM album WHERE owner='”+uid+”‘ AND type=’profile’ )”;
    data.return_ssl_resources = 0;
    albumLoader = facebook.call(“method/fql.query”, data, URLRequestMethod.POST, null, “https://api.facebook.com”);

    albumLoader.addEventListener(FacebookOAuthGraphEvent.DATA, onGetAllphotos);

    regards!

  408. muudles May 11, 2011 04:30

    Hi,

    Thank you so much for your hard work.

    I’m testing out your flash example. But I seems to be getting erratic results after logging in and out. Sometimes it only say ‘connecting’, sometimes ‘connecting, authorizing’, sometimes ‘connecting, authorizing and uploading’. The image only successfully uploaded onto my fb ones.

    I tried looking through the comments just in case you’ve already answered it, but I didn’t seem to see anyone else with the same problem?

    Please help.
    Maggie

  409. Jozef Chúťka May 11, 2011 09:32

    hi muudles,
    I am not able to reproduce any issues, it seems like example is working correctly for me. maybe you could debug request being called to see if there are any issues with connection – response by facebook

  410. Eulochi July 19, 2011 18:10

    Hello,

    Will this work on a mobile device, especially if I’m making a Flash app for ios?

    Many thanks.

  411. Jozef Chúťka July 19, 2011 18:19

    Hi Eulochi,
    if ios supports StageWebView you should be able to use this source
    http://blog.yoz.sk/2010/10/authorizing-facebook-applications-in-android/

  412. […] It does not provide login authentication as there are many other libraries available for this purpose and really…why re-invent the wheel? Some great examples are from Big Spaceship and Jozef Chúťka. […]

  413. Rana August 12, 2011 08:59

    Nice one good for flash people

  414. Rana August 12, 2011 09:19

    Hi man,

    Thanks for this source !here the issue is
    i implemented expectantly in flex but i will get the same will get the same window which is visible on the top . when am clicking that button it gos to the Facebook login page other button are enabled how to share videos and images in Facebook

  415. Rana August 12, 2011 09:20

    and how to create the like button and share button in my Flex ui

  416. Jozef Chúťka August 12, 2011 09:54

    hi Rana,
    for like button read this article again there is a section “Hi Is there a way to implement a “i Like” button with your class?”

    for uploading images to facebook:
    http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/

  417. Create Your Own August 19, 2011 02:46

    Great post! I will try to add this inside to my flash game.

  418. […] […]

  419. aravindakumar September 12, 2011 14:58

    Hi,
    Great post!how to get the current user session?

  420. Jozef Chúťka September 13, 2011 09:07

    hi aravindakumar,
    you mean FacebookOAuthGraph.token?

  421. Mike Delucchi October 3, 2011 01:00

    or you could just use this method… with the new 1.7 api (http://code.google.com/p/facebook-actionscript-api)

    here’s a snippet from a game i’m building on facebook that requires permissions at a certain point in the game.. it works well

    private function facebookInit():void // START THE SESSION…
    {
    Cc.add (‘facebookInit — v 8.0′);

    Facebook.init(APP_ID, facebookInitHandler,{
    appId: APP_ID,
    status: true,
    cookie: true,
    xfmbl: true,
    channelUrl: ‘http://yoursiteurl/channel.html’,
    oauth: true,
    perms: “publish_stream,email”});
    }

    private function facebookInitHandler(response:Object, fail:Object):void
    {
    if (response.accessToken)
    {
    userAccessToken = JSON.encode(response.accessToken);
    facebookLoggedInWithToken = true;
    loadProfileData();
    } else {
    facebookLoggedInWithToken = false;
    }
    }

    private function loadProfileData():void
    {
    var request:String = ‘/me';
    var requestType:String = ‘GET';
    var params:Object = null;
    Facebook.api(request, loadProfileDataHandler, params, requestType);
    }

    private function loadProfileDataHandler(response:Object, fail:Object):void
    {
    if (response) {
    userID = response.id;
    fullName = response.name;
    firstName = response.first_name;
    lastName = response.last_name;
    userEmail = response.email;
    userPicURL = ‘http://graph.facebook.com/’ + userID + ‘/picture';
    }
    }

    enjoy!

  422. PVieira October 7, 2011 18:34

    Hi Jeff! I was seeing some new stuff from facebook and I saw this article:
    http://digitizor.com/2011/01/24/tag-user-facebook-graph/

    I’ve tried to do a feed with that code: attachment.description = “Friend: @[{uid}:1:{name}]”

    Didn’t work. I wonder if you already tried this successfully?

  423. Jozef Chúťka October 10, 2011 09:47

    hi PVieira,
    I have not tryed it yet myself… however
    “I’ve tried to do a feed with that code: attachment.description = “Friend: @[{uid}:1:{name}]”” … I believe it works only on message feeds, not attachments

  424. PVieira October 10, 2011 11:11

    Thanks for the answer Josef. I tried also in data.message so it seems it really doesn’t work.

    Is there a way to send a message to a user friend? Some notification that my app is using his data?

  425. Jozef Chúťka October 10, 2011 12:05
  426. PVieira October 10, 2011 13:46

    Yes, I saw that information in other forum. So there is no alternative? That sucks but I understand facebook position.

  427. RT_Magstar November 8, 2011 07:18

    can anybody guide me how to invite friends for events using graph api ( post method ) in c# example.

  428. Sam December 21, 2011 17:45

    All seems to work great! I can post photo’s from my flash App to facebook :)

    Although my Facebook permission window is opened in a new tab, not a nice small popup. What can this problem be? Thanks in advance people.

  429. Jozef Chúťka December 21, 2011 18:02

    hi Sam, if this also happens for you with the flash example in this blog post than it is related to your webbrowser. else make sure the window in your code is opened via javascript:window.open

  430. Gil December 21, 2011 22:59

    I using the the code above and so far all is great (Many thanks) How would I go about having the post to an image where by the pop up to add additiona text to your wall is present.

    Thanks

  431. Jozef Chúťka December 22, 2011 10:41

    hi Gil, please read http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/ and comments under, there is a lot of useful stuff and tips

  432. Henry January 31, 2012 06:09

    is there an updated facebook app settings configuration now that facebook has changed it?

  433. Jozef Chúťka January 31, 2012 14:41

    Henry, I have updated those in article, I hope it helps you

  434. Ilya February 9, 2012 17:05

    Hi,

    Once again I am using it, and once again great job!

    I translated your sample to flash builder 4.6 style, tell me if you need the code.

  435. Ilya February 9, 2012 17:06

    *mail me

  436. norberto tso February 20, 2012 19:55

    i got the flash c4 source code and when i run in flash ide i got the follow message:

    Error #1065: A variável com.adobe.serialization.json::JSON não foi definida.
    at sk.yoz.events::FacebookOAuthGraphEvent/get data()[C:\facebook_11\cs4\src\sk\yoz\events\FacebookOAuthGraphEvent.as:36]
    at sk.yoz.net::FacebookOAuthGraph/verifyTokenSuccess()[C:\facebook_11\cs4\src\sk\yoz\net\FacebookOAuthGraph.as:108]
    at Function/()[C:\facebook_11\cs4\src\sk\yoz\net\FacebookOAuthGraph.as:100]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at sk.yoz.net::FacebookOAuthGraph/loaderComplete()[C:\facebook_11\cs4\src\sk\yoz\net\FacebookOAuthGraph.as:186]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()

    help me please

  437. Jozef Chúťka February 21, 2012 10:09

    norberto, I think you are missing JSON library. try downloading it from http://code.google.com/p/as3corelib/

  438. aarti gusain April 11, 2012 09:02

    hi jozef

    I am using your code for facebook authantication and it perfactly run but i am faceing problem regarding facebook access token url,when we run our app on facebook we get a authantication popup .my question is you without opening the popup can we get access token.

    i am using this code in flash and in flash side we call “advancedcallback.html” .can we use php side code for access token handling?if yes,please guide me how we write that

  439. Jozef Chúťka April 11, 2012 10:19

    hi aarti, you should be able to access token on php, there is an php api documentation on https://developers.facebook.com/docs/reference/php/facebook-api/ , sending access token from php to flash can be done via flashvars … see “add hash” button functionality in my example

  440. aarti gusain April 17, 2012 07:51

    hi jozef

    Once again i am here with my problem.actually jozef i had tried to solve the access token according to your suggestion but our team want to solve this problem in flash side completely,can you please suggest me how we get access token without open the popup.

    when we run our app on crome and if my popup setting is blocked ,in this case authantication popup does’nt open and my app is autherized completely and i get my all friends information,but when i run my app on mozzila and ie browser and we blocked our popup setting, in this case our app does not autherized and we do not get any friends information,so in this case my functionality do not work and its a big issue ,that’s why i want to try to get access token without opening any popup.
    if you have any solution please suggest me .

  441. Jozef Chúťka April 18, 2012 09:28

    aarti, in order to get access token you must visit facebook page with authorization for your app. you can do it in popup or redirecting whole page (I would expect frames to not to work to avoid clickjacking). offline access seems to be depricated https://developers.facebook.com/roadmap/#may-2012 so user will have to reauthenticate with every new session – popup or redirect

  442. Ttcat May 10, 2012 23:27

    Hi,

    Thanks for your project ! I got same problem about open a small popup window. It just open up a new tab or window. I looked into the Class, it looks ok !

    Wonder if there’s other MUST HAVE js code in html ?

    public function connect():void
    {
    if(!tokenCallbackDefined)
    {
    tokenCallbackDefined = true;
    ExternalInterface.addCallback(jsConfirm, confirmConnection);
    }

    var id:String = ExternalInterface.objectID;
    var url:String = authorizationURL;
    var name:String = jsWindowName;
    var props:String = “width=670,height=370″;
    var js:String = ”
    + ‘if(!window.’ + jsConfirm + ‘){‘
    + ‘ window.’ + jsConfirm + ‘ = function(hash){‘
    + ‘ var flash = document.getElementById(“‘ + id + ‘”);’
    + ‘ flash.’ + jsConfirm + ‘(hash);’
    + ‘ }’
    + ‘};’
    + ‘window.open(“‘ + url + ‘”, “‘ + name + ‘”, “‘ + props + ‘”);’

    ExternalInterface.call(“function(){” + js + “}”);
    }

  443. Jozef Chúťka May 11, 2012 11:32

    Hi Ttcat,
    you do not need to have any additional code in javascript, you can define all needed via ExternalInterface, just make “Make sure your html wrapper defines correct allowScriptAccess and both id and name for tag.”

  444. Vaishali Saxena June 7, 2012 11:59

    will you please resolve my query i have implemented your code it is connected with the application but not authrized…this function not call and add hash is also not called..
    so please resolve my query..

  445. Vaishali Saxena June 7, 2012 13:47

    My flash code is not connected with my Facebook application. I can not resolve the error and not getting the error that what and where is the problem..
    on click the connect button the window show my application on logging into the account it appears the message
    “You may now close this window.”
    not connected with the application..
    I can’t debug ma flash application..
    please give me some solution how to resolve it..

  446. Jozef Chúťka June 7, 2012 14:05

    Hi Vaishali,
    I have no idea what might went wrong based on your description. I suggest you debug flash callback method as well as javascript part.

  447. Vaishali Saxena June 12, 2012 08:38

    I used your above code my application perfectly run and update the status, now i want to add the additional feature for uploading the photo using the above code…
    Can u send me the code to upload the photo on Facebook just like to update the status on the above code..
    Thanx in advance….

  448. Jozef Chúťka June 12, 2012 09:14