July 9, 2012

Hacking Facebook API again. How to close user session properly

Unfortunately, Facebook API changes frequently forcing developers to write new code and check regularly that everything runs smoothly. In specific situations as a desktop AIR app that works for multiple users, it is extremely important that users can logout correctly. If they can not, something wrong will happen!

Facebook Graph API released by Adobe is out of day, logout operation is malfunctioning. The code is as follows:

if (session != null) {
    params.access_token = session.accessToken;
}
params.method = "auth.logout";
params.next = "http://static.ak.fbcdn.net/connect/xd_proxy.php#origin="+(appOrigin?appOrigin:"");
var req:FacebookRequest = new FacebookRequest();
openRequests[req] = handleLogout;
req.call("https://www.facebook.com/logout.php", 'GET', handleRequestLoad, params);

Without going into details, everything seems to be correct unless the parameter next, which defines the address where the browser is redirected after logging off. The address must match exactly with the address defined in the configuration panel, inside Facebook Developers site:

Site URL facebook app

Configuración de la aplicación

Then, to close the session properly, we just have to change the next parameter line as follows:

if (session != null) {
    params.access_token = session.accessToken;
}
params.method = "auth.logout";
params.next = appOrigin;  // cambio!
var req:FacebookRequest = new FacebookRequest();
openRequests[req] = handleLogout;
req.call("https://www.facebook.com/logout.php", 'GET', handleRequestLoad, params);

and the code will work properly.

Post a Reply

Your email address will not be published. Required fields are marked *