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 . 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.
, thnx
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
[...] (May 5, 2010): I have created Facebook Graph API & OAuth 2.0 & Flash – FacebookOAuthGraph ActionScript 3 class to use with OAuth 2.0 and [...]
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?
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
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…
argh it didin’t wrote my embed code, but i don’t think is so useful
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);
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?
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/
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!
thanks Kevin, glad to hear that
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 !!
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.
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)
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
Thanks!!!!!
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.
I put together an example app at git hub for those struggling with facebook and air:
http://github.com/josefsalyer/Facebook-Flex-Example-App
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
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_
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/ .
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
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);
}
Hi Jozef,
Thanks for the Charles Proxy link. It looks like something very useful indeed.
It works properly now.
Greetings from Belgium.
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,
jk: http://blog.yoz.sk/2010/05/facebook-graph-api-and-oauth-2-and-flash/#comment-1783
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
@Jozef Chúťka
Thanks… i haven’t thought that well..
Cheers.
Josep
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?
Thanks, Jozef, I appreciate the quick response.
Cheers!
JT
@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
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
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
Hi Jozef,
Thanks for the update!
It’s a sad news.
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
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.
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_
Link to the article
Sorry, it seems that i forgot to close a tag in my previous post.
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
Please support this bug with your vote, on official facebook bugzilla, it may help:
http://bugs.developers.facebook.com/show_bug.cgi?id=10055
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
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
@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
@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.
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.
——- Comment #12 From Jeff Bowen 2010-05-17 13:56:45 ——-
This should be fixed with Tuesday’s push. Stay tuned.
:O
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…
atleast I didnt
…
@Chris
We all did!
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!
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 ?
good news everyone – secure is false
https://graph.facebook.com/crossdomain.xml
and application is working again!
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.
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
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!
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?
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?
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
Hi Dan,
well ok,
am I JC?
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)
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
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.
@Dan, that reminds me C.J. from BayWatch
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
@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
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
@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
@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
It works like a charm!
Thanks Jozef for the updates.
Greetings from Belgium.
You’re genius! Just let me try it and I’ll tell you how it worked out, thanx a million
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
just noticed i do not get any permission popup on safari (windows) or chrome (windows). ie and firefox do work…
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
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
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.
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.
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!
@Morten, if this issue persist even after clearing your browser cache, pleas report it as a bug
@Morten to log-out user, it is enough to clear the SharedObject (contains access_token)
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?
@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;
}
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
@Jey you should do it this way:
var data:URLVariables = new URLVariables();
data.type = “large”
call(“me/picture”, data);
Tks for the update !
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?
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
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.
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?
@Sean thnx for posting working solution
Is not permission problem because me/albums worked ok.
@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
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?
me/albums work
me/feed work
changeStatus work
but me/photos – empty… i don’t fking understand
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.
look, about same problem talking here http://forum.developers.facebook.com/viewtopic.php?pid=223727
and here http://forum.developers.facebook.com/viewtopic.php?pid=225939#p225939
look like bug… http://bugs.developers.facebook.com/show_bug.cgi?id=10083
@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
yes, it look like solution, but… still not working
maybe cache or something… i try it from another pc…
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?
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.
From another pc, after new autorization me/photos worked.
Jozef thanks, i’ll go to create AMAZING application.
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.
why am I getting a strange window within a window when doing a iFrame canvas app
?
i ofc mean iFrame with a iFrame inside
nvm .. stumbled upon this
http://labs.byhook.com/2010/05/19/facebookery-the-flash-and-facebook-how-to/
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)
@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.
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…
@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”;
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 !
Hello, well I’m back to tell you how things are working out for me trying to make my iframe app work.
I tried to implement the steps of “How can I use this class in my iframe canvas page?” but I’m afraid that I had the same problem described here http://forum.developers.facebook.com/viewtopic.php?pid=228774
The good news is that someone posted a working solution to this(answers #13 from jasek2)that consists on having an index.php which only function is to make a redirect and having the rest of the application in another folder, the redirect uri MUST be to that folder, e.g. http://apps.facebook.com/appname/callback/ .Then you can retrieve a var called ‘code’ and ask for ‘acess_token’ using your ‘code’,'client_id’, ‘redirect_uri’ and ‘client_secret’. Once you get your ‘acess_token’ you can send it via flashvars to the flex app. This is how I did it, it’s a mix of Jozef’s exellent app and the solution of facebook forum:
Index.php on http://yourserver/appname/:
<?
echo "”;
echo “window.open(‘https://graph.facebook.com/oauth/authorize?client_id=xxxxx&redirect_uri=http://apps.facebook.com/appname/callback/&scope=xxxxx’, ‘_parent’, ”)”;
echo ” “;
?>
Index.php on http://yourserver/appname/callback:
<?php
$code = $_GET["code"];
$token = file_get_contents('https://graph.facebook.com/oauth/access_token?client_id=xxxxx&client_secret=xxxxx&redirect_uri=http://apps.facebook.com/appname/callback/&code='.$code.'');
echo 'var flashVars = {access_token:”‘.$token.’”};var params = {wmode:”opaque”,allowScriptAccess: “sameDomain”};var attributes = {id: “FacebookOAuthGraphTest”,name: “FacebookOAuthGraphTest”};swfobject.embedSWF(“myswf.swf”, “flashDiv”, “600″, “400″, “10.0.0″, “expressInstall.swf”, flashVars, params, attributes);’;
?>
On Flex app:
public var myToken:String;
private function initfb():void
{
facebook.clientId = clientId;
facebook.redirectURI = redirectURI;
facebook.scope = scope;
facebook.useSecuredPath = true;
facebook.addEventListener(FacebookOAuthGraphEvent.AUTHORIZED, authorized);
facebook.checkSavedToken();
myToken=this.loaderInfo.parameters.access_token;
facebook.confirmConnection(myToken);
}
—–
This is working for me BUT on the same thread on facebook forum (answer #21) someone is asking about how safe is to pass the client_secret on the url. I have the same doubt but I see no other way to get the acess_token. Even facebook suggest passing the client_secret on the url here http://developers.facebook.com/docs/authentication/ :
* After the user authorizes your application, we redirect the user back to the redirect URI you specified with a verification string in the argument code, which can be exchanged for an oauth access token. Exchange it for an access token by fetching https://graph.facebook.com/oauth/access_token. Pass the exact same redirect_uri as in the previous step:
https://graph.facebook.com/oauth/access_token?
client_id=…&
redirect_uri=http://www.example.com/oauth_redirect&
client_secret=…&
code=…
I’m really concerned about safety, so even if this is working, I don’t know how risky is to pass the client_secret on the url. What do you think? What do you recommend? :S
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…
@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…).
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.
@Pieter ok, or you can do it with URLVariables … read FAQ / “How to add request parameters into my call?”
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 ()
[...] 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 [...]
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.
@James ok I will take a look at it
@Marc I have been doing some minor changes lately… anyway can you replicate the issues?
@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);
}
@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
@James ok mate, I have just fixed the error issue. please update
Thank you very much. I will give it a try!
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!
Hi Donovan, I will take a look at it
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
@Donovan, updated, please download latest FacebookOAuthGraph, its compatible with flash authoring tool compiler. http://blog.yoz.sk/examples/FacebookOAuthGraph/cs.as
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”
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
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 !
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
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”);
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..
you are almost there Carl, now all you have to do is to debug what comes in hash variable when cancel is clicked
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.
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
@josep again pls, what should your button do?
sorry the code is ,
but i´m almost sure that it is the wrong way to go
The button should add my application to a tab on the user profile.
http://wiki.developers.facebook.com/index.php/Fb:add-profile-tab
@josep how does this relate to the actionscript class?
@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.
@Nick parameters are flashvars: stage.root.loaderInfo.parameters
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. =)
@Paulo, please use callComplete() from my example. It works. Maybe the FBGraphEvents class you use is problematic. FacebookOAuthGraphEvent works fine…
@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.
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
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()
@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
@markval override loaderAddListeners() and loaderRemoveListeners() and add security error handler like so:
type = SecurityErrorEvent.SECURITY_ERROR;
loader.addEventListener(type, loaderSecurityError);
[...] The Facebook Graph API article becomes pretty popular and a lot of developers keep asking me to publish some practices I use, I [...]
Hi Josef. Thank you for taking the time to respond to my (and the many other) questions. Your help is greatly appreciated.
Sincerely,
Jaglavek
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
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.
hi,
When I am running your app I am getting this error from Facebook: “An error occurred. Please try again later.”
Any ideas?
@Ilya I guess it is one of the facebook’s api common error, please try again later.
Yeah defiantly, the question is there any thing I can do to fix it?
Oh nvm, I forgot the init() when moving to flash builder…
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.
Thanks for posting on this, I found your examples useful and have managed to get Graph API auth & calls working now. Thanks again.
That’s what I figured. Thanks Jozef.
@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/
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
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
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?
http://winxalex.blogspot.com/2010/06/facebook-graph-and-aouth-api-in-flex-4.html
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…
Ilya, does it work with my app? if so, make sure you use latest class versions + check your facebook app settings
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
Hi per, what are your call() parameters? Is your request domain/path really https://graph.facebook.com/… or is it https://api.facebook.com/… ?
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
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
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. =)
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.."]
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!
Hi Francsico, sorry, but impossible for now… please read updated faq
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?
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
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_
@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
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
@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_
Jk_, Carol X funny, my app works for me in IE8… I have FP 10,1,53,64 debug / ActiveX / IE8 / win xp
Hi francisco Chong,
parameters are flashvars (stage.root.loaderInfo.parameters) , you can use parametrs variable in flex Application element
@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
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
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
@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.
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.
@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?
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
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
[...] 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 [...]
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!
hi Jozef
thanks for this – you continue to do amazing work
Cheers
@Rapha, yes it shuould work just fine with proxy
@Daniel, thank you
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
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!
@Jason, unable to make it modal, facebook does not let you open its content in iframe anymore (clickjacking)
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 ?
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
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
@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”
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);
…and the src in the media is a valid url to an image BTW
)
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…
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 ?
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
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 ?
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
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.
js function confirmFacebookConnection() is injected from actionscript when connecting
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.
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.
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
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
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
@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
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?
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.
@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
@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.
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.
@Dionysius yes it may be some app settings, see http://blog.yoz.sk/examples/FacebookOAuthGraph/settings.png
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?
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.
@Francisco, do i get it right – the popup is opened and the request to secured facebook page blocked?
@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
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
@Steve very nice solution, thank you for sharing
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.
@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?
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
@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
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?
@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.
After I tried this setting, it doesnt work again.
anyway…i just hope facebook quick fix it now.
thank you for your help.^^
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?
Could this also be related to the IE facebook bug you mentioned? I put 100 votes on it.
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
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. =(
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
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.
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.
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!
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
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
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.
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.
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?
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.
@shammi, Im glad you did it
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
Hi Adam, i guess its due to missing permissions, try “user_photos,user_photo_video_tags”
Thanks for that Jozef – I had ‘user_photos’ but not user_photo_video_tags’ added – this seems to have made the difference.
Cheers
Adam
Is it possible to get the person e-mail?
@PVieira yes, extended permission “email”, more here http://developers.facebook.com/docs/authentication/permissions
[...] Facebook Graph API & OAuth 2.0 & Flash (update) [...]
Jk_ .. could you send me your example.. i am trying to do what you did exacly but i am having a ton of issues
[...] 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. [...]
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
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.
[...] Facebook Graph API & OAuth 2.0 & Flash (update) [...]
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
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?
Hi @Herdiansah, thanx for your logout method, briliant idea!
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)
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?
@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
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
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″
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?
Only works with “me/picture” call, with “{uid}/picture” gives me an error..
Hi Jozef,
Did you manage to get worked this beautiful class and your great stuff with flex iframe?
Regards
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?
@PVieira it surely works, even without access_token:
https://graph.facebook.com/jozefchutka/picture
http://graph.facebook.com/jozefchutka/picture
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)
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.
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”
I solved the problem with picture, but only with access_token, i can’t test this localy. Well, it works.
PVieira, you can change “FacebookOAuthGraphTest” to anything… both id and name are required keys for flash attributes (used with ExternalInterface)
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
}
I think the problem is this line that i don’t understand:
var session:Object = JSON.decode(parameters.session);
Any ideia what might be?
IE working thanks to a comment tip from @tom: http://blog.yoz.sk/2010/05/facebook-graph-api-and-oauth-2-and-flash/#comment-2816
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?
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
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
Thanks, i will try to change that.
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
[...] 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 [...]
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
Hi @verg, please read here
http://blog.yoz.sk/2010/09/authorizing-facebook-applications-in-air/
[...] 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 [...]
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?
Hi @verg,
you see, there is a lot of null parameters in your url, you have to fix that first
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.
can someone compare http://code.google.com/p/fbas/ vs http://github.com/yourpalmark/facebook-actionscript-api
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!
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
@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…
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.
[...] 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. [...]
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/
Hi Jozef,
Is there anyway to opening the facebook login in an iframe rather than opening in a popup window?
Thanks,
Herdiansah
Hi @Herdiansah,
it is not possible, facebook blocks its content within iframe, you can make simple test… I guess due to clickjacking it is
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?
hi! i would like to use the FLEX example from above in FLASH.
what do i need to change? please help!
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/
@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
i don’t get it to work in FLASH. are there any code or file downloads available please?
thanks
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?
@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
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?
@Porter, it seems like you are having issue with javascript, is your swfobject.js file located correctly?
yes it’s in the same folder. (swfobject 2.2)
anybody experienced the same problem? WindowsXP with IE / Firefox / Chrome / Opera
@Porter, its definitely a javascript issue, make sure your javascript is correct… I can see undefined variable flashvars etc… use firebug to debug javascript
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
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/ )
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
Hi david,
why do you let your script call connect when you are connected already? use FacebookOAuthGraph.authorized to show/hide connect button etc.
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.
@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
ok, it was the shared object that was missing me…
i’ll test it..
thank you
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!
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
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.)
@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
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!
@jiannis, do you use debug player? what is the Exception being thrown?
@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!
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
Nevermind got it working now
Thanks for posting this article, really helped me out!
C
@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
@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
@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!!
@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
@jozef, got it! thanks a million!
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.
Soleh Ayubi, it seems like you are not using FacebookOAuthGraph library but the official Adobe one, please ask the question on their discussion forum
How can i get wall photos?
@PVieira me/feed to get feeds on wall, then iterate and get those with image attachments
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…
@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?
[...] Facebook AS3 Graph API 的作法,請參照 Jozef Chúťka 前輩所寫的 Facebook Graph API & OAuth 2.0 & Flash (update) [...]
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
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
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
robrob, you are welcome
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
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
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’);
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
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”
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
@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
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
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
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
When I call me/feed it doesnt return anything?
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?
Hi magicDamo, you have to use rest api call with FQL:
http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/ see section “Application Friends”
@Don, it is a standard http request, it must return something even if it was an error code. please debug and trace the response
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/
Sorry Jozef it returns blank data
{
“data”: [
]
}
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
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!
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?
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
hi Ellis, you can call “/me” to get info about logged user
Thanks Jozef, very cool what you have done here!
Sorted my problem with the me/feed with read_stream permission.
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.
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?
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…
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
[...] Facebook AS3 Connect 方法在此一樣不提,請自行參考教學連結。 [...]
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…
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!
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”
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
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
@Jozef, thanks for your reply. The small window problem was a mistake on my part.
Thanks for sharing this great solution too!
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!
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.
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.
Hi gilles,
you can use this lib anywhere. If you are able to pass token into flashvars you will get connected
great thanks, I’ll try. so it’s the only way left to make interactive app in a fan tab.
thanks again
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.
gilles, can you debug the exception? on what line does it throw this exception?
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.
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.
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…
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
??
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
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
@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.
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!
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
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,,
thx before :cheers:
Hi Donny,
JSON is not a property but a class. you can import one from original adobe package
import com.adobe.serialization.json.JSON
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
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
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
)
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.”
Hi Paul,
thank you for your feedback, one really should override clone method when extending Event… I have updated the FacebookOAuthGraphEvent file.
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!
Nim, there are changes everyday… but, if you are trying to access data with a token, make sure its secured request – https://… !
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.
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
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
Marco check out latests updates on http://blog.yoz.sk/2010/06/authorizing-iframe-facebook-applications-for-graph-api
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.
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!
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
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
Hello,
Will this work on a mobile device, especially if I’m making a Flash app for ios?
Many thanks.
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/
[...] 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. [...]
Nice one good for flash people
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
and how to create the like button and share button in my Flex ui
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/
Great post! I will try to add this inside to my flash game.
[...] [...]
Hi,
Great post!how to get the current user session?
hi aravindakumar,
you mean FacebookOAuthGraph.token?
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!
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?
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
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?
notifications are depricated, see http://stackoverflow.com/questions/2574431/facebook-api-send-messages-to-friends
Yes, I saw that information in other forum. So there is no alternative? That sucks but I understand facebook position.
can anybody guide me how to invite friends for events using graph api ( post method ) in c# example.
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.
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
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
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
is there an updated facebook app settings configuration now that facebook has changed it?
Henry, I have updated those in article, I hope it helps you
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.
*mail me
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
norberto, I think you are missing JSON library. try downloading it from http://code.google.com/p/as3corelib/
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
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
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 .
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
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 + “}”);
}
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
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..
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..
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.
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….
hi Vaishali, have a look at http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/
Hey! I know this is somewhat off topic but I was
wondering which blog platform are you using for this site?
I’m getting fed up of WordPress because I’ve had issues with hackers
and I’m looking at options for another platform. I would be awesome if you could point me in the direction of a good platform.
Inez
Inez, wordpress it is…