Facebook Cookbook - Jay Goldman [137]
Getting a Session (Desktop Only)
Problem
I have my auth_token and created my session, but now I need to retrieve it again after switching from HTTP to HTTPS.
Solution
If you established a session over HTTP but need to switch to HTTPS, you can retrieve a session key again by calling Auth.getSession() and passing in the auth_token you got when you called Auth.createToken().
Discussion
This isn’t required by web apps, as there’s currently no way for a user to interact with your app over an HTTPS connection to http://apps.facebook.com (it will either bounce them back to HTTP automatically or give an error about using a security certificate for the wrong domain).
You can also pass a generate_session_secret boolean into Auth.getSession() if you’d like it to generate and return a temporary secret key associated with the session. You can use that secret instead of your app’s API secret key for the duration of this session.
Creating an Auth Token (Desktop Only)
Problem
I need to create an auth token for my desktop Facebook app.
Solution
Use the Auth.createToken() method, which requires no parameters beyond the standard api_key, sig, and version, and returns a key that can be used to create a session (see Creating a Session Key for more info).
Discussion
This isn’t required by web apps, which can just go directly to creating a session key.
Making Calls (Desktop Only)
Problem
How do I make a call to the Facebook API server from my desktop app?
Solution
Generally speaking, you prepare a request and then transmit it to the API server (see http://api.facebook.com/restserver.php) using POST over the HTTP protocol. The server will return an XML response.
Discussion
You could write your own code to manage the Facebook session and handle the server communication, but you might want to leverage the excellent work other people have been doing and use one of these libraries instead:
.NET
Facebook and Microsoft have partnered to provide a Facebook Developer Kit built on Popfly and Visual Studio Express. You can get more information and downloads at http://www.microsoft.com/express/samples/facebook/. Even more information is available on CodePlex at http://www.codeplex.com/FacebookToolkit. An alternate library, Facebook.NET, which includes support for C# and VB.NET, can be found on CodePlex at http://www.codeplex.com/FacebookNET.
ActionScript
The facebook-actionscript-api is an MIT-licensed library for secure communication between Flash/Flex apps and the Facebook server, written and maintained by Jason Crist. More information and downloads are available at http://code.google.com/p/facebook-actionscript-api/.
Java
Facebook used to provide an official Java Client Library, but it has subsequently been discontinued. The facebook-java-api project has taken over with an open source version, which you can download at http://code.google.com/p/facebook-java-api/.
Ruby on Rails
Check out the Facebooker project at http://facebooker.rubyforge.org/. It’s conveniently packaged as a gem, so you can just gem install facebooker.
Qt+KDE
Linux developers should check out the libkfacebook project, which is an asynchronous, GPL-licensed library for talking to the Facebook API with responses mapped to C++ objects. You can grab the source from Subversion at svn://anonsvn.kde.org/home/kde/trunk/playground/pim/kfacebook.
VB.NET
Independent developer Jay Lagorio has released a Client Library for Facebook that supports the API version 1.0 in VB.NET. More information and downloads are at http://www.lagorio.net/windows/facebook/.
You need to create an and , respectively, for more information on those processes.auth_token and then instantiate a session before you can make most of the calls in the API (but not, obviously, before you