'. '

Facebook

From APIDesign

(Difference between revisions)
Jump to: navigation, search
(Facebook Desktop Application)
Line 3: Line 3:
=== [[Facebook]] Desktop Application ===
=== [[Facebook]] Desktop Application ===
-
[[TBD]]
+
I can't help myself, as a founder of [[NetBeans]] I still feel like a desktop guys. As a result I wanted to access [[Facebook]] from my desktop application. Actually, I'd even wanted to create an application that can run headless, on a server. I wanted to create a [[RSS]] feed publisher. An application that can read [[Blogs|my blog]] entries and post them up on my [[facebook]] page.
-
# Register your application at http://www.facebook.com/developers/createapp.php
+
This is not easy. Desktop applications are not the primary target of [[facebook]] and it is hard to find good tutorial, even harder to find some that are modestly up to date. However I made it work. If you want to make your application work too, here is the howto. I am sure it is not perfect, however please note that this is a [[wikipedia:mediawiki|wiki page]]. Everyone can make it better. If you know better way to do some of the tasks, feel free to update the page.
-
# Sources: http://source.apidesign.org/hg/feedbook/
+
 
-
# Builds, downloads: http://hudson.apidesign.org/hudson/job/feedbook
+
==== Register ====
 +
 
 +
The first step is to register at http://www.facebook.com/developers/createapp.php and obtain your application key and secret. It does not matter much what values you put in the registration form. None are important as far as I can tell.
 +
 
 +
==== Login ====
 +
 
 +
Having your key and secret you can start writing your application. Sources of mine ''feedbook'' are available in a [[Hg]] repository: http://source.apidesign.org/hg/feedbook/, you can use:
 +
 
 +
<source lang="bash">
 +
$ hg clone http://source.apidesign.org/hg/feedbook/
 +
$ cd feedbook
 +
$ mvn install
 +
</source>
 +
 
 +
to get them and compile them. First thing to do is to login and obtain a session ID:
<source lang="java" snippet="feedbook-login"/>
<source lang="java" snippet="feedbook-login"/>
 +
 +
Alas, I don't know how to login using pure [[REST]] [[API]]s. As such I have to open a browser and let the user login manually. I'd rather prefer to login in a headless mode, but seeking the Internet did not help me at all to find a way to do it.
 +
 +
[[TBD]]
 +
 +
# Builds, downloads: http://hudson.apidesign.org/hudson/job/feedbook

Revision as of 22:18, 11 November 2010

While ago I got a question from a curious to-become-reader of TheAPIBook whether, after reading it, he will be able to create API for a Web OS like Facebook. I had to admit that my book could help only indirectly. Some principles apply, but the main focus is on libraries, while Facebook is more about REST APIs. Anyway, modernity cannot be prevented, so I am slowly deep diving into this slightly different world too.

Facebook Desktop Application

I can't help myself, as a founder of NetBeans I still feel like a desktop guys. As a result I wanted to access Facebook from my desktop application. Actually, I'd even wanted to create an application that can run headless, on a server. I wanted to create a RSS feed publisher. An application that can read my blog entries and post them up on my facebook page.

This is not easy. Desktop applications are not the primary target of facebook and it is hard to find good tutorial, even harder to find some that are modestly up to date. However I made it work. If you want to make your application work too, here is the howto. I am sure it is not perfect, however please note that this is a wiki page. Everyone can make it better. If you know better way to do some of the tasks, feel free to update the page.

Register

The first step is to register at http://www.facebook.com/developers/createapp.php and obtain your application key and secret. It does not matter much what values you put in the registration form. None are important as far as I can tell.

Login

Having your key and secret you can start writing your application. Sources of mine feedbook are available in a Hg repository: http://source.apidesign.org/hg/feedbook/, you can use:

$ hg clone http://source.apidesign.org/hg/feedbook/
$ cd feedbook
$ mvn install

to get them and compile them. First thing to do is to login and obtain a session ID:

Code from Main.java:
See the whole file.

private static String login() 
throws IOException, FacebookException, URISyntaxException {
    FacebookJaxbRestClient login = new FacebookJaxbRestClient(
        APP_KEY, APP_SEC
    );
    final String token = login.auth_createToken();
    final URI u = new URI("http://www.facebook.com/login.php?"
            + "api_key=" + APP_KEY + "&auth_token=" + token);
    String msg = "authentication";
    browser(msg, u);
    return login.auth_getSession(token, false); 
}
 

Alas, I don't know how to login using pure REST APIs. As such I have to open a browser and let the user login manually. I'd rather prefer to login in a headless mode, but seeking the Internet did not help me at all to find a way to do it.

TBD

  1. Builds, downloads: http://hudson.apidesign.org/hudson/job/feedbook
Personal tools
buy