Monday, January 17, 2011

The Facebook login & logout flow for Android platform

Recently I am working on a mobile application project using the FaceBook API. I never touched Facebook API before, for me the first thing is to understand how the Facebook login/logout works on the mobile apps, so I spent some time on figure out how does it work on the Android platform.

I just summarized the login and logout flow based on the Facebook android SDK source code and its sample app log output.

First you need to register your application and get your application ID from the facebook website.

Login Flow

Request format:

client_id is your application id.
display=touch means the device smart phone (android or iphone)


You need to launch a browser inside your app to send the login the request, browser will display a login dialog let input the facebook account and password, then if login successful, the browser will return the redirected URL(fbconnect://success) with the access_token and expired value.

To retrieve these values, you need to intercept the redirected URL: check if it starts with fbconnect://success, then parse the response, get the access_token and expire value.

Logout Flow
format:[your access_token]

If logout successfully, the response will return text "true",
otherwise it will return a JSON text contains the detailed error message.