Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): fix illust_comments method #379

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions pixivpy3/aapi.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested it? Wont' it cause problems if altered to ajax api instead of app-api?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, of course I have tested it. There's already a similar method that uses ajax API. That's why I proposed this way

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how to do this via app API. If there's a working one, please propose

Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,23 @@ def illust_comments(
include_total_comments: str | bool | None = None,
req_auth: bool = True,
) -> ParsedJson:
url = f"{self.hosts}/v1/illust/comments"
url = "https://www.pixiv.net/ajax/illusts/comments/roots"
# Web API,伪造Chrome的User-Agent
headers = {
"User-Agent": (
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 "
+ "(KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
),
"Referer": "https://www.pixiv.net",
}
params = {
"illust_id": illust_id,
}
if offset:
params["offset"] = offset
if include_total_comments:
params["include_total_comments"] = self.format_bool(include_total_comments)
r = self.no_auth_requests_call("GET", url, params=params, req_auth=req_auth)
r = self.no_auth_requests_call("GET", url, headers=headers, params=params, req_auth=req_auth)
return self.parse_result(r)

# 相关作品列表
Expand Down
Loading