No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Runnnig Sample

This is a sample J2ME social gaming app made using App42 backened platform. It uses social, user, storage and gaming APIs of App42 platform. Here are the few easy steps to run this sample app.

  1. [Register] ( with App42 platform
  2. Create an app once you are on Quick-start page after registration.
  3. Goto dashboard and create a new game TrafficJunkie (Click on Gaming->Games->Add Game->)
  4. If you are already registered, login to [AppHQ] ( console and create an app from App Manager tab and do step #3 to create a game.
  5. Download the eclipse project from this repo and import it in the same.
  6. Open in sample app and give the value of app42APIkey app42SecretKey that you have received in step 2 or 4
  7. You can also modify your fbAppId and fbAppSecret variable to pass your own facebook app credentials. Read our [blog post] ( for more help about creating facebook app and its configuration.
  8. Build and Run

Design Details:

Initialize Services:

Initialization has been done in

	  	ServiceAPI sp = new ServiceAPI(app42APIkey,app42SecretKey);
	    	this.scoreBoardService = sp.buildScoreBoardService();
	    	this.storageService = sp.buildStorageService();
	    	this.socialService = sp.buildSocialService();
    	}catch(Exception e){

Get Facebook Access Token:

This call is in

  String token = socialService.doFBOAuthAndGetToken(startMIDlet, fbAppId,null);

Fetch Facebook Profile From Access Token:

This call is in

  Social social = socialService.getFacebookProfile(oauthToken);
  UserContext.MyUserName = social.getFacebookProfile().getId();
  UserContext.MyDisplayName = social.getFacebookProfile().getName();
  UserContext.MyPicUrl = social.getFacebookProfile().getPicture();

Store User Profile: This is to srore User Profile(Facebook Id, Display Name, PicURL etc.) By saving user profile we can retrive display name for facebook id(Used to create friends leaderboard)

This call is done in

    JSONObject userProfile = new JSONObject();
    try {
        userProfile.put("UserName", UserContext.MyUserName);
        userProfile.put("DisplayName", UserContext.MyDisplayName);
        userProfile.put("PicUrl", UserContext.MyPicUrl);
        storageService.insertJSONDocument(Constants.ZAPAK_DB_NAME, Constants.USER_PROFILE_COLLECTION, userProfile.toString());
    } catch (Exception e) {

Save Score:

This call is in

   Game game = scoreBoardService.saveUserScore(gameName, name, score);

Get LeaderBoard:

This call is in

   Game game = scoreBoardService.getTopNRankers(currentGameName, new Integer(20));

Get Facebook Friends:

This call is in

    final Social social = socialService.getFacebookFriendsFromAccessToken(oauthToken);

For friends Leaderboard:

   Game game = scoreBoardService.getTopNRankersByGroup(currentGameName, group);

here group is a vector for facebook ids of your friends. Now we retive display name for facebook ids from Storage Service that we used earlier.