Talking about Actionscript 3, Facebook, Flash and Php.
It’s time to make some considerations on the Facebook application made with the Facebook Actionscript API I blogged some days ago.
There was a doubt about putting a secret key in the swf
file.
Well, you should never give away your secret key, but let me point on two things:
1) You can encrypt your swf
file, obfuscating the secret key… and just in case you think nothing is encrypted enough… surprise…
2) My Facebook application works without api and secret keys. That’s it… I tested it with more than one account, and everybody was able to use the application even if my keys are stored this way:
var api_key:String="xxxxxxxxxxxxxxxxxxxxxxx";
var secret_key:String="yyyyyyyyyyyyyyyyyyyyyyy";
I am not hiding them, they are really a series of x
and y
… probably when you render a swf
in canvas
mode, they aren’t mandatory.
I have to say, I did not find docs about it, so take it as it comes.
The feature introduce this time is showing all your friends… there was a reader that was unable to populate a list with friend names, so here it is.
I didn’t create any list, but I’m simply showing them in a text area.
package {
import flash.display.Sprite;
import fl.controls.Button;
import flash.events.MouseEvent;
import flash.text.TextField;
// facebook libraries
import com.facebook.Facebook;
import com.facebook.utils.FacebookSessionUtil;
import com.facebook.commands.notifications.*;
import com.facebook.commands.friends.*;
import com.facebook.commands.stream.*;
import com.facebook.commands.users.*;
import com.facebook.events.*;
import com.facebook.data.users.*;
import com.facebook.data.friends.*;
import com.facebook.net.FacebookCall;
public class facebook_demo extends Sprite {
var vars_field:TextField=new TextField ;
var friends_field:TextField=new TextField ;
var my_button:Button;
var fbook:Facebook;
// these are the api and secret keys you should be used to
var api_key:String="xxxxxxxxxxxxxxxxxxxxxxx";
var secret_key:String="yyyyyyyyyyyyyyyyyyyyyyy";
// starting a new facebook session
var fb_session:FacebookSessionUtil=new FacebookSessionUtil(api_key,secret_key,loaderInfo);
// in this object I will store all variables Facebook will pass to the movie
var passed_vars:Object;
// this variable will hold all facebook API calls
var fbcall:FacebookCall;
public function facebook_demo() {
// just placing some buttons...
place_buttons();
// just creating a text field...
create_vars_field();
// initializing the session
fbook=fb_session.facebook;
// this function will just print out all variables Facebook is passing to the movie
get_vars();
// getting friends uids (unique ids)
fbcall = new GetFriends();
fbook.post(fbcall);
// function on_get_friends will be called once the post is completed
fbcall.addEventListener(FacebookEvent.COMPLETE, on_get_friends);
}
// function to be called after GetFriends has finished
function on_get_friends(e:FacebookEvent):void {
var friends = (e.data as GetFriendsData).friends;
var friends_num:int=friends.length;
var uids:Array = new Array();
// loading all friends uids into an array
for (var i:int=0; iFacebook Flash Demo","user_to_user");
fbook.post(fbcall);
break;
case "Publish a story" :
// publishing a story
fbcall=new PublishPost("is using Facebook Flash Demo",{'href':'http://apps.facebook.com/flash_demo/','name':'Facebook Flash Demo','description':'that\'s it','caption':'this image was published by a Flash Movie','media':[{'type': 'image','src': 'http://www.gamemummy.com/facebook/flash_demo/api.jpg', 'href': 'http://apps.facebook.com/flash_demo/'}]},[{'href':'http://apps.facebook.com/flash_demo/','text':'Visit Facebook Flash Demo'}],uid.toString());
fbook.post(fbcall);
break;
}
}
function create_vars_field():void {
addChild(vars_field);
vars_field.width=340;
vars_field.height=320;
vars_field.x=0;
vars_field.y=10;
vars_field.text="DEFAULT VARS PASSED BY FACEBOOK:\n\n";
addChild(friends_field);
friends_field.width=340;
friends_field.height=320;
friends_field.x=350;
friends_field.y=10;
friends_field.text="YOUR FACEBOOK FRIENDS (scroll with mousewheel):\n\n";
}
function get_vars():void {
var varname:String;
var varvalue:String;
passed_vars=root.loaderInfo.parameters;
for (varname in passed_vars) {
varvalue=String(passed_vars[varname]);
vars_field.appendText(varname+":\t"+varvalue+"\n");
}
}
function place_buttons():void {
var bnames:Array=new Array("Publish a note","Publish a story");
for (var i:int=0; i<2; i++) {
my_button=new Button ;
addChild(my_button);
my_button.label=bnames[i];
my_button.move(225+150*i,350);
my_button.addEventListener(MouseEvent.CLICK,onclick);
}
}
}
}
The result as usual is on the application page and there is no need to download anything since you can just try it by just cutting/pasting the code on the example you can find at this link.
Can you all make the application work without api and secret keys?
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.