Skip to content

Instantly share code, notes, and snippets.

@andkon
Last active March 5, 2021 19:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andkon/3edd038c12c7f0451573fed550ee6e3d to your computer and use it in GitHub Desktop.
Save andkon/3edd038c12c7f0451573fed550ee6e3d to your computer and use it in GitHub Desktop.
Archive all posts on instagram
from instagram_private_api import Client, ClientCompatPatch
from instagram_private_api.errors import ClientError
username = ""
password = ""
api = Client(username, password) # have to disable 2fa
posts = []
user_feed = api.user_feed(api.authenticated_user_id, max_id="")
posts.extend(user_feed['items'])
while user_feed['more_available'] == True:
user_feed = api.user_feed(api.authenticated_user_id, max_id=user_feed['next_max_id'])
posts.extend(user_feed['items'])
print(len(posts))
for post in posts:
try:
api.media_only_me(post['id'], post['media_type'])
except ClientError as e:
print(f"Error: {e}, for {post['id']}")
continue
if post['caption']:
print(f"Archived {post['caption']['text']}")
else:
print(f"Archived post {post['id']}")
instagram-private-api @ git+https://git@github.com/ping/instagram_private_api.git@1d70e99bc11591161b0cd71cff3f0c08cd04b34f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment