Skip to content

Commit f760a95

Browse files
author
Anonymous Committer
committed
feat: add xiaohongshu API
1 parent 14e8782 commit f760a95

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

justoneapi/apis/xiaohongshu.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ def get_note_detail_v7(self, note_id: str):
4343
}
4444
return request_util.get_request(url, params)
4545

46+
def get_note_detail_v8(self, note_id: str):
47+
url = f"{config.BASE_URL}/api/xiaohongshu/get-note-detail/v8"
48+
params = {
49+
"token": self.token,
50+
"noteId": note_id,
51+
}
52+
return request_util.get_request(url, params)
53+
4654
def get_note_comment_v2(self, note_id: str, last_cursor: str = None):
4755
url = f"{config.BASE_URL}/api/xiaohongshu/get-note-comment/v2"
4856
params = {
@@ -63,6 +71,26 @@ def get_note_comment_v2(self, note_id: str, last_cursor: str = None):
6371
logger.warning(f"Pagination parse error at {url}. Contact us to fix it.")
6472
return result, data, message, has_next_page
6573

74+
def get_note_comment_v3(self, note_id: str, last_cursor: str = None):
75+
url = f"{config.BASE_URL}/api/xiaohongshu/get-note-comment/v3"
76+
params = {
77+
"token": self.token,
78+
"noteId": note_id,
79+
}
80+
if last_cursor:
81+
params["lastCursor"] = last_cursor
82+
83+
has_next_page = False
84+
result, data, message = request_util.get_request_page(url, params)
85+
try:
86+
if data:
87+
has_more = data.get("has_more")
88+
if has_more is not None and isinstance(has_more, bool) and has_more is True:
89+
has_next_page = True
90+
except Exception as e:
91+
logger.warning(f"Pagination parse error at {url}. Contact us to fix it.")
92+
return result, data, message, has_next_page
93+
6694
def get_note_sub_comment_v2(self, note_id: str, comment_id: str, last_cursor: str = None):
6795
url = f"{config.BASE_URL}/api/xiaohongshu/get-note-sub-comment/v2"
6896
params = {
@@ -84,6 +112,27 @@ def get_note_sub_comment_v2(self, note_id: str, comment_id: str, last_cursor: st
84112
logger.warning(f"Pagination parse error at {url}. Contact us to fix it.")
85113
return result, data, message, has_next_page
86114

115+
def get_note_sub_comment_v3(self, note_id: str, comment_id: str, last_cursor: str = None):
116+
url = f"{config.BASE_URL}/api/xiaohongshu/get-note-sub-comment/v3"
117+
params = {
118+
"token": self.token,
119+
"noteId": note_id,
120+
"commentId": comment_id,
121+
}
122+
if last_cursor:
123+
params["lastCursor"] = last_cursor
124+
125+
has_next_page = False
126+
result, data, message = request_util.get_request_page(url, params)
127+
try:
128+
if data:
129+
has_more = data.get("has_more")
130+
if has_more is not None and isinstance(has_more, bool) and has_more is True:
131+
has_next_page = True
132+
except Exception as e:
133+
logger.warning(f"Pagination parse error at {url}. Contact us to fix it.")
134+
return result, data, message, has_next_page
135+
87136
def search_note_v2(self, keyword: str, page: int, sort: str, note_type: str, note_time: str = None):
88137
url = f"{config.BASE_URL}/api/xiaohongshu/search-note/v2"
89138
params = {
@@ -108,6 +157,28 @@ def search_note_v2(self, keyword: str, page: int, sort: str, note_type: str, not
108157
logger.warning(f"Pagination parse error at {url}. Contact us to fix it.")
109158
return result, data, message, has_next_page
110159

160+
def search_note_v3(self, keyword: str, page: int, sort: str, note_type: str):
161+
url = f"{config.BASE_URL}/api/xiaohongshu/search-note/v3"
162+
params = {
163+
"token": self.token,
164+
"keyword": keyword,
165+
"page": page,
166+
"sort": sort,
167+
"noteType": note_type,
168+
}
169+
170+
has_next_page = False
171+
result, data, message = request_util.get_request_page(url, params)
172+
try:
173+
if data:
174+
if data.get("items"):
175+
has_more = data.get("has_more")
176+
if has_more is None or (isinstance(has_more, bool) and has_more is True):
177+
has_next_page = True
178+
except Exception as e:
179+
logger.warning(f"Pagination parse error at {url}. Contact us to fix it.")
180+
return result, data, message, has_next_page
181+
111182
def search_user_v2(self, keyword: str, page: int):
112183
url = f"{config.BASE_URL}/api/xiaohongshu/search-user/v2"
113184
params = {

0 commit comments

Comments
 (0)