mirror of
https://github.com/instaloader/instaloader.git
synced 2026-10-16 13:48:03 -07:00
Fix get_feed_posts() with the api/v1/feed/timeline endpoint
The GraphQL query used so far now returns edge_web_feed_timeline: null, which raised a TypeError. Page through api/v1/feed/timeline/ instead and convert its media items (iPhone format). Fixes #2556
This commit is contained in:
@@ -12,7 +12,7 @@ from datetime import datetime, timezone
|
|||||||
from functools import wraps
|
from functools import wraps
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Callable, IO, Iterator, List, Optional, Set, Union, cast
|
from typing import Any, Callable, Dict, IO, Iterator, List, Optional, Set, Union, cast
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@@ -1095,22 +1095,16 @@ class Instaloader:
|
|||||||
:raises LoginRequiredException: If called without being logged in.
|
:raises LoginRequiredException: If called without being logged in.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
data = self.context.graphql_query("d6f4427fbe92d846298cf93df0b937d3", {})["data"]
|
params: Dict[str, Any] = {}
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
feed = data["user"]["edge_web_feed_timeline"]
|
data = self.context.get_json("api/v1/feed/timeline/", params=params)
|
||||||
for edge in feed["edges"]:
|
for item in data.get("feed_items", []):
|
||||||
node = edge["node"]
|
media = item.get("media_or_ad")
|
||||||
if node.get("__typename") in Post.supported_graphql_types() and node.get("shortcode") is not None:
|
if media and media.get("code") and media.get("ad_id") is None:
|
||||||
yield Post(self.context, node)
|
yield Post.from_iphone_struct(self.context, media)
|
||||||
if not feed["page_info"]["has_next_page"]:
|
if not (data.get("more_available") and data.get("next_max_id")):
|
||||||
break
|
break
|
||||||
data = self.context.graphql_query("d6f4427fbe92d846298cf93df0b937d3",
|
params = {"max_id": data["next_max_id"]}
|
||||||
{'fetch_media_item_count': 12,
|
|
||||||
'fetch_media_item_cursor': feed["page_info"]["end_cursor"],
|
|
||||||
'fetch_comment_count': 4,
|
|
||||||
'fetch_like': 10,
|
|
||||||
'has_stories': False})["data"]
|
|
||||||
|
|
||||||
@_requires_login
|
@_requires_login
|
||||||
def download_feed_posts(self, max_count: Optional[int] = None, fast_update: bool = False,
|
def download_feed_posts(self, max_count: Optional[int] = None, fast_update: bool = False,
|
||||||
|
|||||||
Reference in New Issue
Block a user