k-shimi musicTech-life

Blog by Shimon Koifman

Facebook and external services

Posted by shimikoif on April 13, 2008

How to create mobile service as Facebook application…

Creating an application that will run on top of Facebook platform is an easy journey…
You should have knowledge in web applications life-cycle as well as some programing capabilities in Java,PHP or Python (JavaScript/AJAX is also an option).

The difficult part is when you want:

  • The application to perform tasks that are on-behalf of the users
  • To enable user activity on disconnected mode (from mobile device – without a browser)

Luckily… Facebook platform DO provide facilities to overcome the problems mentioned above.

They (Facebook) call them “infinite session keys”.

Here is what you need to do (In Java):

  • Generate a one time code by accessing the following URL in a browser: http://www.facebook.com/code_gen.php?v=1.0&api_key=YOUR_API_KEY

  • Use the generated code instead of the auth_token that is normally passed to the auth.getSession.
  • The session returned from this call is known as your “Infinite Session Key” and can be used to setup in any external program. e.g.

    FacebookRestClient facebookRestClient = new FacebookRestClient(apiKey, secretKey);
    facebookRestClient.auth_getSession(oneTimeCode); // get infinite session using the one time code

  • That’s it! Your external program should now be able to access the Facebook API just as if it was running inside Facebook
Advertisements

5 Responses to “Facebook and external services”

  1. Thanhy Mather said

    The infinite session does not work for me. I’m using facebook-java-api version 1.7.4. What version of facebook-java-api are you using?

    –Thanhy

    Facebook returns error code 100com.facebook.api.FacebookException: Invalid parameter
    – v -> 1.0
    – method -> facebook.auth.getSession
    – auth_token -> 2DHTHX
    – api_key -> b88724402068294fee6ef246ca7948ab
    – sig -> 38560e35c72403db4b6d2b56ae065e9a

    at com.facebook.api.FacebookRestClient.callMethod(FacebookRestClient.java:790)
    at com.facebook.api.FacebookRestClient.callMethod(FacebookRestClient.java:544)
    at com.facebook.api.FacebookRestClient.auth_getSession(FacebookRestClient.java:1888)

  2. shimikoif said

    Hi,

    You shouldn’t use/depand on the parameter but rather the generated token created by the URL provided. then, save it locally and use it all the time.

  3. Justin said

    Hi,
    Thanks for your post.I tried this with the one time code generated with the given URL.
    But it’s giving the same error “Invalid parameter”.Could you please tell me why it’s throwing this error?

  4. kira said

    I have same error too

  5. kira said

    this error occured when I try to use one time code
    Exception in thread “main” java.lang.NullPointerException
    at com.facebook.api.FacebookRestClient.auth_getSession(FacebookRestClien
    t.java:1899)
    at FacebookGetFriends.main(FacebookGetFriends.java:77)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: