{"id":24986977,"url":"https://github.com/hitthecodelabs/instagrampostsfetcher","last_synced_at":"2026-04-19T13:32:22.120Z","repository":{"id":270508303,"uuid":"910590364","full_name":"hitthecodelabs/InstagramPostsFetcher","owner":"hitthecodelabs","description":"A Python script that fetches Instagram posts from a specified account","archived":false,"fork":false,"pushed_at":"2024-12-31T18:34:25.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T10:47:25.603Z","etag":null,"topics":["graphql","ig","instagram","instaloader","json","request"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hitthecodelabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-31T18:24:30.000Z","updated_at":"2025-01-02T12:10:57.000Z","dependencies_parsed_at":"2025-01-01T00:15:28.468Z","dependency_job_id":null,"html_url":"https://github.com/hitthecodelabs/InstagramPostsFetcher","commit_stats":null,"previous_names":["hitthecodelabs/instagrampostsfetcher"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hitthecodelabs/InstagramPostsFetcher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hitthecodelabs%2FInstagramPostsFetcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hitthecodelabs%2FInstagramPostsFetcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hitthecodelabs%2FInstagramPostsFetcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hitthecodelabs%2FInstagramPostsFetcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hitthecodelabs","download_url":"https://codeload.github.com/hitthecodelabs/InstagramPostsFetcher/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hitthecodelabs%2FInstagramPostsFetcher/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32009119,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T20:23:30.271Z","status":"online","status_checked_at":"2026-04-19T02:00:07.110Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphql","ig","instagram","instaloader","json","request"],"created_at":"2025-02-04T11:34:48.101Z","updated_at":"2026-04-19T13:32:22.102Z","avatar_url":"https://github.com/hitthecodelabs.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Instagram Posts Fetcher\n\nA Python script that fetches Instagram posts from a specified account using a GraphQL endpoint. It supports batching, pagination, and resumable downloads, saving your results into JSON format. It also handles encoding issues for robust JSON loading.\n\n## Features\n\n1. **Batch Fetching**: Pull a specified number of Instagram posts in batches.  \n2. **Pagination**: Uses `after_cursor` to fetch subsequent pages automatically.  \n3. **Resumable**: Keeps track of the last fetched cursor in a state file (`resume_file`) so you can resume fetching later.  \n4. **Flexible Encoding**: Includes error-handling for different text encodings (`utf-8`, `latin-1`, etc.).  \n\n## Requirements\n\n- Python 3.7 or later  \n- [Requests](https://pypi.org/project/requests/) library  \n  ```bash\n  pip install requests\n  ```\n\n- A valid Instagram GraphQL `doc_id` or endpoint (the example uses `doc_id=\"7898261xxxxxxxxxxx\"`, but this can change).\n\n## Installation\n\n1. Clone the repository (or download the script files):\n   ```bash\n   git clone https://github.com/hitthecodelabs/InstagramPostsFetcher.git\n   ```\n\n2. Install Dependencies:\n   ```bash\n   cd InstagramPostsFetcher\n   pip install -r requirements.txt\n   ```\n\n3. If you don't have a requirements file, just ensure `requests` is installed:\n   ```bash\n   pip install requests\n   ```\n\n## Usage\n\n1. Update the Code:\n   - Replace `YOUR_ACCESS_TOKEN` with your token if needed (or remove the Authorization header if you’re not using it).\n   - Make sure your `doc_id` is correct or aligned with the currently valid Instagram GraphQL endpoints.\n\n2. Run the Script:\n   ```bash\n   python ig_posts_fecther.py\n   ```\n\n   By default, it will:\n   - Fetch posts from the specified username (`username`).\n   - Save them to a JSON file (`output_file`, e.g., `instagram_posts_\u003cusername\u003e.json`).\n   - Keep track of pagination state in a resume file (`resume_file`, e.g., `resume_state_\u003cusername\u003e.json`).\n\n3. Check the Output:\n   - After running, open or parse the JSON file to verify the fetched posts.\n   - If you stop the script or if it stops due to an error, just run it again to resume where it left off.\n\n## Script Explanation\n\n- `fetch_instagram_posts(username, after_cursor, post_count)`  \n  Makes a GET request to the Instagram GraphQL endpoint to fetch a specific batch of posts.\n\n- `load_resume_state(resume_file)`  \n  Loads the last pagination state from a JSON file so you can resume from the last cursor.\n\n- `save_resume_state(resume_file, after_cursor, post_count)`  \n  Saves the pagination state after each successful fetch.\n\n- `load_existing_posts(output_file)`  \n  Loads previously saved posts so you can append newly fetched data.\n\n- `iterate_and_save_posts(username, output_file, resume_file, batch_size)`  \n  Orchestrates fetching in batches until there are no more posts or an error occurs.\n\n- `load_json_file(file_path)`  \n  Demonstrates safe reading of JSON files with fallback encodings.\n\n## Troubleshooting\n\n- If Invalid Token errors occur, check your token or authorization method.\n- If the `doc_id` is invalid or outdated, you may see errors from Instagram's GraphQL endpoint. Make sure to update to a valid endpoint or `doc_id`.\n\n## Contributing\n\n1. Fork the project.  \n2. Create your feature branch (`git checkout -b feature/NewFeature`).  \n3. Commit your changes (`git commit -m 'Add a new feature'`).  \n4. Push to the branch (`git push origin feature/NewFeature`).  \n5. Open a Pull Request.  \n\n## License\n\nThis project is licensed under the MIT License. You are free to modify and use the code. Refer to the license file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhitthecodelabs%2Finstagrampostsfetcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhitthecodelabs%2Finstagrampostsfetcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhitthecodelabs%2Finstagrampostsfetcher/lists"}