Skip to content

Commit

Permalink
Upgraded SDK V1.11.8 Add Support V5.1.8 Twitter API
Browse files Browse the repository at this point in the history
  • Loading branch information
Evil0ctal committed Jul 5, 2024
1 parent 136ba6a commit 590f35c
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 4 deletions.
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* [Instagram Web以及APP数据接口](https://api.tikhub.io/#/Instagram-Web-And-APP-API)
* [YouTube Web数据接口](https://api.tikhub.io/#/YouTube-Web-API)
* [网易云音乐App数据接口](https://api.tikhub.io/#/NetEase-Cloud-Music-API)
* [Twitter Web数据接口](https://api.tikhub.io/#/Twitter-Web-API)
* [验证码绕过接口](https://api.tikhub.io/#/Captcha-Solver)
* [临时邮箱接口](https://api.tikhub.io/#/Temp-Mail-API)
* 请将任何问题或错误报告给[Discord服务器](https://discord.gg/aMEAS8Xsvz)
Expand Down Expand Up @@ -173,16 +174,35 @@ self.YouTubeWeb = YouTubeWeb(self.client)
# 网易云音乐APP | NetEase Cloud Music APP
self.NetEaseCloudMusicAppV1 = NetEaseCloudMusicAppV1(self.client)

# Twitter Web | Twitter网页端
self.TwitterWeb = TwitterWeb(self.client)

# Hybrid Parsing
self.HybridParsing = HybridParsing(self.client)
```

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

```python
# 获取单个作品数据 | Get single video data
video_data = await client.DouyinAppV1.fetch_one_video(aweme_id="7345492945006595379")
print(video_data)
# 导入异步io库 | Import asyncio
import asyncio

# 导入tikhub | Import tikhub
from tikhub import Client

# 初始化Client | Initialize Client
client = Client(base_url="https://api.tikhub.io",
api_key="YOUR_API_TOKEN",
proxies=None,
max_retries=3,
max_connections=50,
timeout=60,
max_tasks=50)

if __name__ == "__main__":
# 获取单个作品数据 | Get single video data
video_data = asyncio.run(client.DouyinAppV1.fetch_one_video(aweme_id="7345492945006595379"))
print(video_data)
```

- 我们已经使用HTTPX的对大多数端点进行了异步封装,如果你的代码是同步执行的,你可以使用下面的代码防止异步传染。
Expand Down Expand Up @@ -222,6 +242,11 @@ def fetch_one_video(aweme_id: str):
# 关闭异步事件循环
# Close the asynchronous event
loop.close()

# 调用fetch_one_video方法 | Call the fetch_one_video method
if __name__ == "__main__":
video_data = fetch_one_video(aweme_id="7345492945006595379")
print(video_data)
```

- 由于章节有限,在此处就不列出完整的方法了,你可以通过查看源代码的形式查看每一个属性内实现的方法,每一个方法的命名都是根据端点的`uri`来命名的,例如`/api/v1/douyin/app/v1/fetch_one_video`的方法名就是`fetch_one_video`,你可以根据API文档中的端点来查找对应的方法。
Expand Down
Binary file added dist/tikhub-1.11.9-py3-none-any.whl
Binary file not shown.
Binary file added dist/tikhub-1.11.9.tar.gz
Binary file not shown.
Empty file.
Empty file.
29 changes: 29 additions & 0 deletions tikhub/api/v1/endpoints/twitter/web/twitter_web.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 导入API SDK Client类
import json

from tikhub.http_client.api_client import APIClient


class TwitterWeb:

# 初始化 | Initialize
def __init__(self, client: APIClient):
self.client = client

# Fetch tweet detail | 获取推文详情
async def fetch_tweet_detail(self, focalTweetId: str):
endpoint = "/api/v1/twitter/web/fetch_tweet_detail"
data = await self.client.fetch_get_json(f"{endpoint}?focalTweetId={focalTweetId}")
return data

# Fetch user profile | 获取用户资料
async def fetch_user_profile(self, screen_name: str):
endpoint = "/api/v1/twitter/web/fetch_user_profile"
data = await self.client.fetch_get_json(f"{endpoint}?screen_name={screen_name}")
return data

# Fetch user post tweet | 获取用户发帖
async def fetch_user_post_tweet(self, userId: str, count: int = 20, cursor: str = None):
endpoint = "/api/v1/twitter/web/fetch_user_post_tweet"
data = await self.client.fetch_get_json(f"{endpoint}?userId={userId}&count={count}&cursor={cursor}")
return data
6 changes: 6 additions & 0 deletions tikhub/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
# Hybrid Parsing
from tikhub.api.v1.endpoints.hybrid_parsing.hybrid_parsing import HybridParsing

# Twitter Web
from tikhub.api.v1.endpoints.twitter.web.twitter_web import TwitterWeb


class Client:
def __init__(self,
Expand Down Expand Up @@ -116,5 +119,8 @@ def __init__(self,
# Net Ease Cloud Music
self.NetEaseCloudMusicAppV1 = NetEaseCloudMusicAppV1(self.client)

# Twitter Web
self.TwitterWeb = TwitterWeb(self.client)

# Hybrid Parsing
self.HybridParsing = HybridParsing(self.client)
2 changes: 1 addition & 1 deletion tikhub/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# tikhub/version.py
version = "1.11.8"
version = "1.11.9"

0 comments on commit 590f35c

Please sign in to comment.