Skip to content

Commit 590f35c

Browse files
committed
Upgraded SDK V1.11.8 Add Support V5.1.8 Twitter API
1 parent 136ba6a commit 590f35c

File tree

8 files changed

+64
-4
lines changed

8 files changed

+64
-4
lines changed

README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* [Instagram Web以及APP数据接口](https://api.tikhub.io/#/Instagram-Web-And-APP-API)
2525
* [YouTube Web数据接口](https://api.tikhub.io/#/YouTube-Web-API)
2626
* [网易云音乐App数据接口](https://api.tikhub.io/#/NetEase-Cloud-Music-API)
27+
* [Twitter Web数据接口](https://api.tikhub.io/#/Twitter-Web-API)
2728
* [验证码绕过接口](https://api.tikhub.io/#/Captcha-Solver)
2829
* [临时邮箱接口](https://api.tikhub.io/#/Temp-Mail-API)
2930
* 请将任何问题或错误报告给[Discord服务器](https://discord.gg/aMEAS8Xsvz)
@@ -173,16 +174,35 @@ self.YouTubeWeb = YouTubeWeb(self.client)
173174
# 网易云音乐APP | NetEase Cloud Music APP
174175
self.NetEaseCloudMusicAppV1 = NetEaseCloudMusicAppV1(self.client)
175176

177+
# Twitter Web | Twitter网页端
178+
self.TwitterWeb = TwitterWeb(self.client)
179+
176180
# Hybrid Parsing
177181
self.HybridParsing = HybridParsing(self.client)
178182
```
179183

180184
- 使用`DouyinAppV1``fetch_one_video`方法调用接口获取单一视频数据。
181185

182186
```python
183-
# 获取单个作品数据 | Get single video data
184-
video_data = await client.DouyinAppV1.fetch_one_video(aweme_id="7345492945006595379")
185-
print(video_data)
187+
# 导入异步io库 | Import asyncio
188+
import asyncio
189+
190+
# 导入tikhub | Import tikhub
191+
from tikhub import Client
192+
193+
# 初始化Client | Initialize Client
194+
client = Client(base_url="https://api.tikhub.io",
195+
api_key="YOUR_API_TOKEN",
196+
proxies=None,
197+
max_retries=3,
198+
max_connections=50,
199+
timeout=60,
200+
max_tasks=50)
201+
202+
if __name__ == "__main__":
203+
# 获取单个作品数据 | Get single video data
204+
video_data = asyncio.run(client.DouyinAppV1.fetch_one_video(aweme_id="7345492945006595379"))
205+
print(video_data)
186206
```
187207

188208
- 我们已经使用HTTPX的对大多数端点进行了异步封装,如果你的代码是同步执行的,你可以使用下面的代码防止异步传染。
@@ -222,6 +242,11 @@ def fetch_one_video(aweme_id: str):
222242
# 关闭异步事件循环
223243
# Close the asynchronous event
224244
loop.close()
245+
246+
# 调用fetch_one_video方法 | Call the fetch_one_video method
247+
if __name__ == "__main__":
248+
video_data = fetch_one_video(aweme_id="7345492945006595379")
249+
print(video_data)
225250
```
226251

227252
- 由于章节有限,在此处就不列出完整的方法了,你可以通过查看源代码的形式查看每一个属性内实现的方法,每一个方法的命名都是根据端点的`uri`来命名的,例如`/api/v1/douyin/app/v1/fetch_one_video`的方法名就是`fetch_one_video`,你可以根据API文档中的端点来查找对应的方法。

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

65.6 KB
Binary file not shown.

dist/tikhub-1.11.9.tar.gz

43.9 KB
Binary file not shown.

tikhub/api/v1/endpoints/twitter/__init__.py

Whitespace-only changes.

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

Whitespace-only changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 导入API SDK Client类
2+
import json
3+
4+
from tikhub.http_client.api_client import APIClient
5+
6+
7+
class TwitterWeb:
8+
9+
# 初始化 | Initialize
10+
def __init__(self, client: APIClient):
11+
self.client = client
12+
13+
# Fetch tweet detail | 获取推文详情
14+
async def fetch_tweet_detail(self, focalTweetId: str):
15+
endpoint = "/api/v1/twitter/web/fetch_tweet_detail"
16+
data = await self.client.fetch_get_json(f"{endpoint}?focalTweetId={focalTweetId}")
17+
return data
18+
19+
# Fetch user profile | 获取用户资料
20+
async def fetch_user_profile(self, screen_name: str):
21+
endpoint = "/api/v1/twitter/web/fetch_user_profile"
22+
data = await self.client.fetch_get_json(f"{endpoint}?screen_name={screen_name}")
23+
return data
24+
25+
# Fetch user post tweet | 获取用户发帖
26+
async def fetch_user_post_tweet(self, userId: str, count: int = 20, cursor: str = None):
27+
endpoint = "/api/v1/twitter/web/fetch_user_post_tweet"
28+
data = await self.client.fetch_get_json(f"{endpoint}?userId={userId}&count={count}&cursor={cursor}")
29+
return data

tikhub/client/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
# Hybrid Parsing
4646
from tikhub.api.v1.endpoints.hybrid_parsing.hybrid_parsing import HybridParsing
4747

48+
# Twitter Web
49+
from tikhub.api.v1.endpoints.twitter.web.twitter_web import TwitterWeb
50+
4851

4952
class Client:
5053
def __init__(self,
@@ -116,5 +119,8 @@ def __init__(self,
116119
# Net Ease Cloud Music
117120
self.NetEaseCloudMusicAppV1 = NetEaseCloudMusicAppV1(self.client)
118121

122+
# Twitter Web
123+
self.TwitterWeb = TwitterWeb(self.client)
124+
119125
# Hybrid Parsing
120126
self.HybridParsing = HybridParsing(self.client)

tikhub/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# tikhub/version.py
2-
version = "1.11.8"
2+
version = "1.11.9"

0 commit comments

Comments
 (0)