A python script to download the a conversation in FB. The data Facebook provides in their version is limited. The output is in the a JSON format, separated into individual parts.
Run for both message.py
and all_messages.py
- In Chrome, open facebook.com/messages and open the chat history you would like to save.
- In Chrome Developer tools, open the network tab.
- Scroll up in the conversation until the page attempts to load previous messages
- Look for the POST request to thread_info.php
- You need to input certain parameters from this request into the python script to complete the setup:
- Set the
cookie
value to the value you see in Chrome underRequest Headers
- Set the
__user
value to the value you see in Chrome underForm Data
- Set the
__a
value to the value you see in Chrome underForm Data
- Set the
__dyn
value to the value you see in Chrome underForm Data
- Set the
__req
value to the value you see in Chrome underForm Data
- Set the
fb_dtsg
value to the value you see in Chrome underForm Data
- Set the
ttstamp
value to the value you see in Chrome underForm Data
- Set the
__rev
value to the value you see in Chrome underForm Data
Now downloading messages can proceed.
- Acquire conversation ID by opening http://graph.facebook.com/{username-of-chat-partner}
- Copy the
id
value from there - For group conversations, the ID can be retrieved from the messages tab, as part of the URL. You must use
all_messages.py
instead. - Run the command
python message.py {id} 2000
, and put the value you retrieved for ID earlier
Messages are saved by default to Messages/{id}/
The script can have some trouble with very large conversations (>50k messages). Facebook seems to rate limit this, and returns empty responses. In such cases, the script will retry every 30s until it gets a valid response.
Occasionally, it may take the script several tries to get a valid response.