From IMWiki
Jump to: navigation, search

Facebook uses asynchronous javascript calls (ajax) with responses in javascript object notation (JSON) over an HTTP connection (port 80).

Login is HTTP posted to https://login.facebook.com/login.php with POST data md5pass=0&noerror=1&email={email}&pass={pass} where {email} and {pass} are the user who is logging in's facebook email and password respectively. The cookies that are set by the server must be sent during every POST and GET request to the server(s) below

Every user on Facebook has it's own unique id (UID) number which can be found easiest in the URL of their profile eg "http://www.facebook.com/profile.php?id=1234567890" but can also be done via a search query to http://www.facebook.com/srch.php?nm={search termhere} and is stored in the cookie with name "c_user". Facebook chat uses these UID's for sending and receiving instant messages.

Visibility is updated by sending an HTTP POST to htttp://apps.facebook.com/ajax/chat/settings.php with the POST data visibility=true&post_form_id=1234 where post_form_id is an arbitrary id that will be used throughout the process of communication (the facebook response normally modifies the html that is contained within this form, and needs this id to target it)

The buddy list is fetched via POST to http://apps.facebook.com/ajax/presence/update.php with POST data notifications=1&popped_out=false&force_render=true&buddy_list=1

Previous history of chat with another user is requested via POST to http://apps.facebook.com/ajax/chat/history.php with POST data id=596176850&post_form_id=1234 where id is set to the UID of the user you wish to download history of

Messages are sent via HTTP POST to http://www.facebook.com/ajax/chat/send.php with POST data msg_text={message}&msg_id=3409501070&client_time={timestamp}&to={uid}&popped_out=true&num_tabs=1&post_form_id=1234 where {message} is the urlencoded text that is being sent, {timestamp} is the local unix timestamp of the sender and {uid} is the UID of the user to send to

Messages are retreived by polling http://{1-30}.channel{1-20}.facebook.com/x/{UID}/false/p_{yourUID}={requestnumber}& using an HTTP GET request (not sure what the false bit is, but it can be true too), where the {UID} is the uid of the buddy to download messages from and {requestnumber} is an incrementing number, probably to work around proxy/browser caches. The message that is returned from the server is like

for (;;);{"t":"msg","c":"p_800753867","ms":[{"type":"msg","msg":{"text":"i'm sending u a message","time":1209548203464,"clientTime":1209548202312,"msgID":"3409501070"},"from":800753867,"to":596176850,"from_name":"Eion Robb","to_name":"Jeremy Lawson","from_first_name":"Eion","to_first_name":"Jeremy"}]}

and are in JSON. Messages that are sent to a buddy are also returned back by the server.

Setting a status message is done by POSTing status={status_message_here} to www.facebook.com/updatestatus.php

It has been announced that Facebook will expose an XMPP interface to Facebook's chat and presence.