This script will backup your Instagram account to a GitHub repo and is designed to run via GitHub actions
Before starting, you will need to follow the setup steps on the Facebook Developer Documentation to setup an app, you can also look at this Medium Article or this YouTube Video on how to get an Instagram Token
Basically:
- Create a Facebook App on the Facebook Developer Site
- Add "Instagram Basic Display" as a Product
- Under App > Roles > Instagram Testers add your account as a tester
- Accept the invite at the Instagram Manage Access Page
- Under App > Instagram Basic Display > Basic Display add your account as a tester in the User Token Generator section
Once you've got the token, the application basically uses it to make requests to: and then follow the pagination to retreive all posts
https://graph.instagram.com/me/media?fields=id,caption,media_type,media_url,id&limit=100&access_token=ACCESS_TOKEN
Additionally, the Access token is required in either your environment variables or GitHub secrets (depending on where you're running this)
IG_ACCESS_TOKEN=XXXXXXXXXXXXXXXXXXXX