Over a million developers have joined DZone.

Facebook OAUTH Solutions - Adding Backend to Nokia S40 Apps

DZone's Guide to

Facebook OAUTH Solutions - Adding Backend to Nokia S40 Apps

· Java Zone ·
Free Resource

Get the Edge with a Professional Java IDE. 30-day free trial.

Doing Facbook OAuth on Nokia S40 and J2ME devices is biggest challenge while creating the social apps for this platform becuase of unavailibility of the facebook J2ME SDK and inapp browser limitation of J2ME devices. App42 platform J2ME SDK provides easiest and quickest way to do seamless Facbook OAuth on J2ME devices with out going in the complexity ofunderlying protocol.

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

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.
  • Whole story ends once you got 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 GamingStorageFile StorageMessagingGeo 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.

Article Resource: http://blogs.shephertz.com 

Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}