Warning: the library this script is using to talk to Facebook API (fbchat) is unmaintained at the moment, so you might experience problems with logging in (or be unable to). See fbchat-dev/fbchat#638 and other issues for more info.
Export your personal Facebook chat/Messenger data into an sqlite database.Main difference from “Download your information” export is that this tool can be run automatically and doesn’t require remembering go onto Facebook website, reentering password, downloading archive, etc.
Note that at the moment it exports text only, images or videos are not exported. I recommend checking the database after initial export to make sure it contains everything you want from the tool! I cleaned up some things I assumed weren’t useful from raw responses, but I could be misinterpreting something as I’m not a heavy Facebook user. Feel free to open a github issue if you think something about storage should be changed.
- The easiest way is
pip3 install --user git+https://github.com/karlicoss/fbmessengerexport
.Alternatively, use
git clone --recursive
, orgit pull && git submodule update --init
. After that, you can usepip3 install --editable
. - Login and get cookies:
python3 -m fbmessengerexport.export --login --cookies ANYSTRING
Note: on this step you need to pass an arbitrary string as
--cookies
parameter, just to make the argument parser happy. After login use either the real cookie you got, or the--secrets
parameter (more on that below).Facebook doesn’t have an API, so you’ll have to use cookies.
Ideally this step needs to be done once, after that just use cookies to access your data.
Note that this step might prompt you for two factor auth.
Also Facebook will likely notify you about unusual login, so make sure to approve it in security settings.
Usage:
Recommended: create secrets.py
keeping your api parameters, e.g.:
cookies = '{"c_user": "100000000000000", "datr": "dddddddddddddddddddddddd", "fr": "dlaskjdlakjsldkjL.Alksajdlkjaslkdjalskjdlkajs.lakds1.S-.AAA.0.0.lsakdd.asdasdadasd", "noscript": "1", "sb": "alsjdlasdklajsdlkajsdlad", "xs": "lkajsdalskjdalskjdw%dsd%lksjdlaksjld%lskjdl%lksajds"}'
After that, use:
python3 -m fbmessengerexport.export --secrets /path/to/secrets.py --db /path/to/database/db
That way you type less and have control over where you keep your plaintext secrets.
Alternatively, you can pass parameters directly, e.g.
python3 -m fbmessengerexport.export --cookies <cookies>
However, this is verbose and prone to leaking your keys/tokens/passwords in shell history.
I highly recommend checking exported files at least once just to make sure they contain everything you expect from your export. If not, please feel free to ask or raise an issue!
You can use fbmessengerexport.dal
(stands for “Data Access/Abstraction Layer”) to access your exported data, even offline.
I elaborate on motivation behind it here.
- main usecase is to be imported as python module to allow for programmatic access to your data.
You can find some inspiration in =my.= package that I’m using as an API to all my personal data.
- to test it against your export, simply run:
python3 -m fbmessengerexport.dal --source /path/to/export
- you can also try it interactively:
python3 -m fbmessengerexport.dal --source /path/to/export --interactive