Skip to content

Commit 80ad844

Browse files
committed
Upgraded SDK V1.11.1 Support Xiaohongshu and Kuaishou API
1 parent a039ce6 commit 80ad844

File tree

10 files changed

+98
-30
lines changed

10 files changed

+98
-30
lines changed

README.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ client = Client(base_url="https://api.tikhub.io",
7575
proxies=None,
7676
max_retries=3,
7777
max_connections=50,
78-
timeout=10,
78+
timeout=60,
7979
max_tasks=50)
8080
```
8181

@@ -135,6 +135,12 @@ self.CaptchaSolver = CaptchaSolver(self.client)
135135

136136
# Xigua Video APP V2 | 西瓜视频APP V2
137137
self.XiguaAppV2 = XiguaAppV2(self.client)
138+
139+
# XiaoHongShu Web | 小红书网页端
140+
self.XiaohongshuWeb = XiaohongshuWeb(self.client)
141+
142+
# KuaiShou Web | 快手网页端
143+
self.KuaishouWeb = KuaishouWeb(self.client)
138144
```
139145

140146
- 使用`DouyinAppV1``fetch_one_video`方法调用接口获取单一视频数据。
@@ -148,6 +154,21 @@ print(video_data)
148154
- 我们已经使用HTTPX的对大多数端点进行了异步封装,如果你的代码是同步执行的,你可以使用下面的代码防止异步传染。
149155

150156
```python
157+
# 导入异步io库 | Import asyncio
158+
import asyncio
159+
160+
# 导入tikhub | Import tikhub
161+
from tikhub import Client
162+
163+
# 初始化Client | Initialize Client
164+
client = Client(base_url="https://api.tikhub.io",
165+
api_key="YOUR_API_TOKEN",
166+
proxies=None,
167+
max_retries=3,
168+
max_connections=50,
169+
timeout=60,
170+
max_tasks=50)
171+
151172
# 获取抖音单一视频数据 | Get a single video data from Douyin
152173
def fetch_one_video(aweme_id: str):
153174
# 创建一个异步事件循环

dist/tikhub-1.11.1-py3-none-any.whl

58.9 KB
Binary file not shown.

dist/tikhub-1.11.1.tar.gz

38.7 KB
Binary file not shown.

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
setup(
1515
name="tikhub",
16-
version="1.11.0",
16+
version="1.11.1",
1717
author="TikHub.io",
1818
author_email="[email protected]",
1919
description="A Python SDK for TikHub RESTful API",

tikhub/api/v1/endpoints/kuaishou/web/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# 导入API SDK Client类
2+
import json
3+
4+
from tikhub.http_client.api_client import APIClient
5+
6+
7+
class KuaishouWeb:
8+
9+
def __init__(self, client: APIClient):
10+
self.client = client
11+
12+
# 获取单个作品数据 (Fetch Single Video)
13+
async def fetch_one_video(self, photo_id: str):
14+
endpoint = "/api/v1/kuaishou/web/fetch_one_video"
15+
data = await self.client.fetch_get_json(f"{endpoint}?photo_id={photo_id}")
16+
return data
17+
18+
# 获取单个作品评论数据 (Fetch Single Video Comment Data)
19+
async def fetch_one_video_comment(self, photo_id: str, pcursor: str = None):
20+
endpoint = "/api/v1/kuaishou/web/fetch_one_video_comment"
21+
data = await self.client.fetch_get_json(f"{endpoint}?photo_id={photo_id}&pcursor={pcursor}")
22+
return data
23+
24+
# 获取主页视频数据 (Fetch Home Page Video Data)
25+
async def fetch_home_page_video(self, user_id: str, pcursor: str = None):
26+
endpoint = "/api/v1/kuaishou/web/fetch_home_page_video"
27+
data = await self.client.fetch_get_json(f"{endpoint}?user_id={user_id}&pcursor={pcursor}")
28+
return data
29+
30+
# 获取主页信息数据 (Fetch Home Page Info Data)
31+
async def fetch_home_page_info(self, user_id: str):
32+
endpoint = "/api/v1/kuaishou/web/fetch_home_page_info"
33+
data = await self.client.fetch_get_json(f"{endpoint}?user_id={user_id}")
34+
return data

tikhub/api/v1/endpoints/xiaohongshu/app/xiaohongshu_app.py

-16
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
1-
from fastapi import APIRouter, Query, Request, HTTPException # 导入FastAPI组件
2-
from app.api.v1.models.APIResponseModel import ResponseModel, ErrorResponseModel # 导入响应模型
1+
# 导入API SDK Client类
2+
import json
33

4-
from crawlers.xiaohongshu.web_crawler import *
4+
from tikhub.http_client.api_client import APIClient
55

6-
router = APIRouter()
76

7+
class XiaohongshuWeb:
8+
def __init__(self, client: APIClient):
9+
self.client = client
810

9-
@router.get("/test", response_model=ResponseModel, summary="测试接口")
10-
async def test(request: Request):
11-
# 测试函数
12-
data = {"message": "即将上线,敬请期待 | Coming soon, stay tuned"}
13-
return ResponseModel(code=200,
14-
router=request.url.path,
15-
params=dict(request.query_params),
16-
data=data)
11+
# 获取笔记信息
12+
async def get_note_info(self, note_id: str):
13+
endpoint = "/api/v1/xiaohongshu/web/get_note_info"
14+
data = await self.client.fetch_get_json(f"{endpoint}?note_id={note_id}")
15+
return data
16+
17+
# 获取用户信息
18+
async def get_user_info(self, user_id: str):
19+
endpoint = "/api/v1/xiaohongshu/web/get_user_info"
20+
data = await self.client.fetch_get_json(f"{endpoint}?user_id={user_id}")
21+
return data
22+
23+
# 搜索笔记
24+
async def search_notes(self, keyword: str, page: int = 1, sort: str = "general", noteType: str = "_0"):
25+
endpoint = "/api/v1/xiaohongshu/web/search_notes"
26+
data = await self.client.fetch_get_json(f"{endpoint}?keyword={keyword}&page={page}&sort={sort}&noteType={noteType}")
27+
return data
28+
29+
# 获取用户的笔记
30+
async def get_user_notes(self, user_id: str, lastCursor: str = None):
31+
endpoint = "/api/v1/xiaohongshu/web/get_user_notes"
32+
data = await self.client.fetch_get_json(f"{endpoint}?user_id={user_id}&lastCursor={lastCursor}")
33+
return data

tikhub/client/client.py

+12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
# Xigua Video APP V2
2828
from tikhub.api.v1.endpoints.xigua.app.xigua_app_v2 import XiguaAppV2
2929

30+
# XiaoHongShu Web
31+
from tikhub.api.v1.endpoints.xiaohongshu.web.xiaohongshu_web import XiaohongshuWeb
32+
33+
# KuaiShou Web
34+
from tikhub.api.v1.endpoints.kuaishou.web.kuaishou_web import KuaishouWeb
35+
3036

3137
class Client:
3238
def __init__(self,
@@ -82,3 +88,9 @@ def __init__(self,
8288

8389
# Xigua Video APP V2
8490
self.XiguaAppV2 = XiguaAppV2(self.client)
91+
92+
# XiaoHongShu Web
93+
self.XiaohongshuWeb = XiaohongshuWeb(self.client)
94+
95+
# KuaiShou Web
96+
self.KuaishouWeb = KuaishouWeb(self.client)

0 commit comments

Comments
 (0)