Facebook For Games is a library to facilitate the authentication process of Facebook games. It is an extension of the Facebook Actionscript API, which is packaged within the library with some changes, providing methods for authentication with the ability to check if a user has logged-in within a Facebook web games. The library takes care of all the work related to logging in the user, if they are not logged in already.

Once the game is authenticated, it’s possible to get access to the game’s and user’s scores. The library also makes it extremely easy to save the score to Facebook and to share or post it to the user’s wall.

Main classes:

  • FacebookForGames – handles the authentication and login all under the hood.
  • ShareManager – Allows you to post the the users wall or open a share link popup.
  • ScoreManager – Allows you to get the scores for the game, for the user and the user’s frinds. Also allows you to save the user’s score.
  • FacebookGameModel – Holds all the pertinent session, user and game data.

Data objects:

  • FacebookUser – Holds all the pertinent information for the currently logged in user. An instance of this class for the current user is saved in FacebookGameModel.
  • Score – Holds the score data including the application name and id and also the user name and id as well as their score.



	import com.facebook.graph.controls.Distractor;
	import com.reycogames.facebook.FacebookForGames;
	import com.reycogames.facebook.data.FacebookUser;
	import com.reycogames.facebook.data.PostToWallProperties;
	import com.reycogames.facebook.data.Score;
	import com.reycogames.facebook.manager.ScoreManager;
	import com.reycogames.facebook.manager.ShareManager;
	import com.reycogames.facebook.model.FacebookGameModel;

	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;

	[SWF( width="600", height="450", frameRate="60" )]
	public class FacebookGraphTest extends Sprite
		private var appID:String        = "";
		private var appSecret:String    = "";
		private var permissions:Array   = [ "publish_stream" ];
		private var distractor:Distractor;

		private var someRandomScore:int = 500;

		public function FacebookGraphTest() {
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;

			distractor = new Distractor();
			distractor.text = "Loading";
			addChild( distractor );

			FacebookForGames.authenticate( appID, appSecret, permissions, handleFBInit );

		private function handleFBInit( facebookUser:FacebookUser ):void {
			removeChild( distractor );
			distractor = null;

			trace( FacebookGameModel.currentUser.first_name + " is ready to go!" );
			ScoreManager.getScoresForGame( handleGotScores );

		private function handleGotScores( scores:Vector. ):void {
			for (var a:int = 0; a < scores.length; a++) {
				trace( scores[a].userName, scores[a].score );


		private function sendScores():void {
			ScoreManager.postScore( someRandomScore, handleScorePosted );

		private function handleScorePosted():void {
			trace( "score saved" );

			var postToWallProps:PostToWallProperties = new PostToWallProperties();
			postToWallProps.name = " I just scored " + someRandomScore + "!";
			postToWallProps.description = "[some description about your game]";
			postToWallProps.link = "http://[link to my game].com";
			postToWallProps.picture = "http://[some link to an image]";

			ShareManager.postToWall( postToWallProps, handlePostSuccess );

		private function handlePostSuccess( result:Object ):void {
			trace( "score shared on wall" );
Authentication. URL.