Export Instagram and Facebook comments with Python
Use the Python standard library to export a bounded collection of Instagram or Facebook comments. The downloadable script makes one request by default, keeps keys in your environment and writes a CSV plus a collection report.
Download and review the example
Use Python 3.10 or later. No extra packages are required. Read the script before running it, and set FETCHFOX_API_KEY in your local environment without committing or sharing the value. The example calls api.fetchfox.net directly and does not follow redirects.
Begin with one request
Replace the placeholder URL with one public post that you are permitted to process. With limit 20, a successful request costs one credit; downloading the local CSV costs no additional credits. Choose an output filename that does not already exist.
python3 fetchfox-comments-export.py \
--platform instagram \
--url "https://www.instagram.com/p/REPLACE_SHORTCODE/" \
--limit 20 --pages 1 --output instagram-comments.csvSet an explicit pagination budget
The script permits at most five pages per run and a limit between 1 and 100. The example below requests up to three pages of 20 comments, costing at most three credits when each request succeeds. Successful requests use normal pricing even when cached. With larger limits, the balance pre-check requires one credit per 20 requested, while the final charge is one per 50 returned comments, minimum one per successful request.
A continuation keeps the same post URL and, on Instagram, the same sort order. The script stops on repeated cursors or no new IDs, deduplicates across pages and makes no automatic retries.
python3 fetchfox-comments-export.py \
--platform facebook \
--url "https://www.facebook.com/watch?v=REPLACE_VIDEO_ID" \
--limit 20 --pages 3 --output facebook-comments.csvRead the CSV and collection report
The CSV contains allowlisted fields and protects formula-like text and long numeric identifiers. Missing counts are blank, while source-reported zero stays zero. The companion .report.json records the source URL, retrieval times, pages completed, returned charges and why collection stopped. It does not contain your key or opaque cursors.
If a later request fails, earlier valid rows remain saved and the process exits unsuccessfully so automation can notice. Check the report before starting another run; a new run starts from the first page and successful requests can be charged again. On HTTP 429, the error reports Retry-After when supplied. It never retries for you.
Validation and limits
The downloadable script is exercised against local HTTP fixtures for pagination, duplicate IDs, unknown and zero metrics, spreadsheet formula protection, redirects, HTTP errors and retained partial results. The recorded examples on the viewer pages came from separate live requests on 20 October 2026. Fixture tests do not guarantee that any particular public post will remain available.
The script does not retrieve private content, guarantee all replies, schedule itself or perform sentiment analysis. Treat a collection as a dated sample and retain its source.