From 9eb7bdadfbafb6011de0493eff32f7fde2563a18 Mon Sep 17 00:00:00 2001 From: smolkik-code Date: Wed, 17 Jun 2026 14:56:47 +0700 Subject: [PATCH] fix: use web API for stories (mobile API blocked) - Try www.instagram.com/api/v1/feed/user/{id}/story/ - Desktop Chrome user-agent for web endpoint - Fallback from reels_media POST to web GET --- instagram_monitor.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/instagram_monitor.py b/instagram_monitor.py index 969553b..a602ffe 100644 --- a/instagram_monitor.py +++ b/instagram_monitor.py @@ -215,15 +215,22 @@ class InstagramMonitor: return followees def _get_user_stories(self, user_pk: int) -> list[dict]: - """Fetch stories via reels_media endpoint (returns actual items).""" + """Fetch stories via web API profile endpoint.""" try: - resp = self.session.post( - f"{API_BASE}/feed/reels_media/", - json={"user_ids": [user_pk]}, + # Try web API with ?__a=1&__d=dis + resp = self.session.get( + f"https://www.instagram.com/api/v1/feed/user/{user_pk}/story/", + params={"user_id": user_pk, "__a": "1", "__d": "dis"}, + headers={ + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", + "X-IG-App-ID": "936619743392459", + "X-Requested-With": "XMLHttpRequest", + "Accept": "*/*", + "Referer": f"https://www.instagram.com/", + }, timeout=30, ) if resp.status_code != 200: - logger.debug(f"Stories {user_pk}: HTTP {resp.status_code}") return [] data = resp.json() @@ -239,7 +246,7 @@ class InstagramMonitor: stories.append(item) return stories except Exception as e: - logger.error(f"Error fetching stories for {user_pk}: {e}") + logger.debug(f"Stories {user_pk} error: {e}") return [] def _get_all_stories(self) -> dict[int, list[dict]]: