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
cookievalue to the value you see in Chrome underRequest Headers - Set the
__uservalue to the value you see in Chrome underForm Data - Set the
__avalue to the value you see in Chrome underForm Data - Set the
__dynvalue to the value you see in Chrome underForm Data - Set the
__reqvalue to the value you see in Chrome underForm Data - Set the
fb_dtsgvalue to the value you see in Chrome underForm Data - Set the
ttstampvalue to the value you see in Chrome underForm Data - Set the
__revvalue 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
idvalue from there - For group conversations, the ID can be retrieved from the messages tab, as part of the URL. You must use
all_messages.pyinstead. - 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.