Sunday, September 18, 2011

LWUIT and Facebook API - by Chen Fishbein

Nowadays almost every app needs to be connected to facebook in some level: post a message to your friends wall, post on your wall, like a post, etc...

We are well aware of such need and we are well aware of the lack of support for J2ME devices.
Connect an app to facebook sounds something trivial that every smart phone is doing very easily, but doing the same on a J2ME device is almost impossible.

Facebook uses Oauth2 to authenticate which basically means you need a browser to display the login page and the ability to handle a session on the client until login is authenticated.

In the last couple of months we worked very hard to finally offer such solution to LWUIT developers, now you can use a very simple API to access Facebook.(it's important to note that this won't work on all J2ME devices, due to a relatively new/complex certificate facebook is using, which some old devices has difficulties with, even the good old WTK won't work - this will require a nokia SDK or the upcoming SDK 3.0.5 from Oracle which should be released soon)

The new API has a new Demo which is available from our svn:
https://svn.java.net/svn/lwuit~svn/trunk/Apps/FaceBookDemo

In addition we created an official facebook lwuit page which is open for lwuit discussions


Some API samples:

//authenticate your facebook app with the permissions you need
FaceBookAccess.getInstance().authenticate(appid, redirect_uri, new String[]{"user_photos", "friends_photos", "publish_stream", "read_stream", "user_relationships", "user_birthday", "friends_birthday", "friends_relationships", "read_mailbox", "user_events", "friends_events", "user_about_me"});

//then create a User Object and ask the FaceBookAccess to fill it with the data
User me = new User();
FaceBookAccess.getInstance().getUser("me", me, null);

0 comments:

Post a Comment