181 lines
4.5 KiB
Markdown
181 lines
4.5 KiB
Markdown
|
|
# TikHub API 模块
|
|||
|
|
|
|||
|
|
本模块提供了统一的 TikHub 接口调用中间层,支持多种平台的 API 接口。
|
|||
|
|
|
|||
|
|
## 目录结构
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
tikhub/
|
|||
|
|
├── types.js # 枚举定义:InterfaceType、MethodType
|
|||
|
|
├── tikhub.js # 核心服务类 TikhubService
|
|||
|
|
├── index.js # 统一导出入口
|
|||
|
|
├── example.js # 使用示例
|
|||
|
|
└── README.md # 本文档
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 快速开始
|
|||
|
|
|
|||
|
|
### 1. 导入模块
|
|||
|
|
|
|||
|
|
```javascript
|
|||
|
|
import TikhubService, { InterfaceType, MethodType } from '@/api/tikhub'
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 2. 调用接口
|
|||
|
|
|
|||
|
|
```javascript
|
|||
|
|
// 调用抖音热门搜索接口
|
|||
|
|
const response = await TikhubService.postTikHup(
|
|||
|
|
InterfaceType.DOUYIN_WEB_HOT_SEARCH, // 接口类型
|
|||
|
|
MethodType.GET, // HTTP 方法
|
|||
|
|
{ keyword: '测试关键词' } // 实际接口参数
|
|||
|
|
)
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## API 说明
|
|||
|
|
|
|||
|
|
### TikhubService.postTikHup(type, methodType, urlParams)
|
|||
|
|
|
|||
|
|
统一调用 TikHub 接口的中间层方法。
|
|||
|
|
|
|||
|
|
**参数:**
|
|||
|
|
- `type` (String) - 接口类型,使用 `InterfaceType` 枚举值
|
|||
|
|
- `methodType` (String) - HTTP 方法类型,使用 `MethodType` 枚举值
|
|||
|
|
- `urlParams` (Object|String) - 实际接口的参数
|
|||
|
|
|
|||
|
|
**返回:**
|
|||
|
|
- Promise - axios 响应对象
|
|||
|
|
|
|||
|
|
**示例:**
|
|||
|
|
|
|||
|
|
```javascript
|
|||
|
|
// 获取小红书热门榜单
|
|||
|
|
await TikhubService.postTikHup(
|
|||
|
|
InterfaceType.XIAOHONGSHU_WEB_HOT_LIST,
|
|||
|
|
MethodType.GET,
|
|||
|
|
{ page: 1, page_size: 20 }
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
// 搜索抖音内容
|
|||
|
|
await TikhubService.postTikHup(
|
|||
|
|
InterfaceType.DOUYIN_GENERAL_SEARCH_V4,
|
|||
|
|
MethodType.POST,
|
|||
|
|
{
|
|||
|
|
keyword: '热门内容',
|
|||
|
|
sort_type: 0,
|
|||
|
|
publish_time: 0,
|
|||
|
|
}
|
|||
|
|
)
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 枚举说明
|
|||
|
|
|
|||
|
|
### InterfaceType - 接口类型
|
|||
|
|
|
|||
|
|
支持的所有接口类型:
|
|||
|
|
|
|||
|
|
| 枚举值 | 说明 |
|
|||
|
|
|--------|------|
|
|||
|
|
| `XIAOHONGSHU_USER_INFO` | 小红书 - 获取用户信息 |
|
|||
|
|
| `DOUYIN_WEB_USER_POST_VIDEOS` | 抖音 - 网页端获取用户发布的视频 |
|
|||
|
|
| `DOUYIN_APP_USER_POST_VIDEOS` | 抖音 - APP端V3获取用户发布的视频 |
|
|||
|
|
| `DOUYIN_APP_GENERAL_SEARCH` | 抖音 - APP端V3通用搜索结果 |
|
|||
|
|
| `DOUYIN_SEARCH_SUGGEST` | 抖音 - 搜索建议 |
|
|||
|
|
| `DOUYIN_GENERAL_SEARCH_V4` | 抖音 - 通用搜索V4 |
|
|||
|
|
| `XIAOHONGSHU_WEB_HOT_LIST` | 小红书 - 网页端V2热门榜单 |
|
|||
|
|
| `DOUYIN_WEB_HOT_SEARCH` | 抖音 - 网页端热门搜索结果 |
|
|||
|
|
| `KUAISHOU_WEB_HOT_LIST` | 快手 - 网页端热门榜单V2 |
|
|||
|
|
| `BILIBILI_WEB_POPULAR` | B站 - 网页端流行内容 |
|
|||
|
|
| `WEIBO_WEB_HOT_SEARCH` | 微博 - 网页端V2热门搜索指数 |
|
|||
|
|
| `DOUYIN_WEB_GENERAL_SEARCH` | 抖音 - 网页端通用搜索结果 |
|
|||
|
|
|
|||
|
|
### MethodType - HTTP 方法
|
|||
|
|
|
|||
|
|
| 枚举值 | 说明 |
|
|||
|
|
|--------|------|
|
|||
|
|
| `GET` | GET 请求 |
|
|||
|
|
| `POST` | POST 请求 |
|
|||
|
|
| `PUT` | PUT 请求 |
|
|||
|
|
| `DELETE` | DELETE 请求 |
|
|||
|
|
| `PATCH` | PATCH 请求 |
|
|||
|
|
|
|||
|
|
## 使用示例
|
|||
|
|
|
|||
|
|
详细的使用示例请参考 `example.js` 文件。
|
|||
|
|
|
|||
|
|
### 示例 1:获取抖音热门搜索
|
|||
|
|
|
|||
|
|
```javascript
|
|||
|
|
import TikhubService, { InterfaceType, MethodType } from '@/api/tikhub'
|
|||
|
|
|
|||
|
|
async function getDouyinHotSearch() {
|
|||
|
|
try {
|
|||
|
|
const response = await TikhubService.postTikHup(
|
|||
|
|
InterfaceType.DOUYIN_WEB_HOT_SEARCH,
|
|||
|
|
MethodType.GET,
|
|||
|
|
{ keyword: '测试关键词' }
|
|||
|
|
)
|
|||
|
|
return response
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('调用失败:', error)
|
|||
|
|
throw error
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 示例 2:获取用户发布的视频
|
|||
|
|
|
|||
|
|
```javascript
|
|||
|
|
async function getUserVideos() {
|
|||
|
|
return await TikhubService.postTikHup(
|
|||
|
|
InterfaceType.DOUYIN_WEB_USER_POST_VIDEOS,
|
|||
|
|
MethodType.GET,
|
|||
|
|
{
|
|||
|
|
sec_user_id: 'MS4wLjABAAAxxxxxxxx',
|
|||
|
|
count: 20,
|
|||
|
|
max_cursor: 0,
|
|||
|
|
}
|
|||
|
|
)
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 错误处理
|
|||
|
|
|
|||
|
|
```javascript
|
|||
|
|
try {
|
|||
|
|
const response = await TikhubService.postTikHup(
|
|||
|
|
InterfaceType.DOUYIN_WEB_HOT_SEARCH,
|
|||
|
|
MethodType.GET,
|
|||
|
|
{ keyword: '测试' }
|
|||
|
|
)
|
|||
|
|
console.log('成功:', response)
|
|||
|
|
} catch (error) {
|
|||
|
|
if (error.message.includes('无效的接口类型')) {
|
|||
|
|
console.error('接口类型错误')
|
|||
|
|
} else {
|
|||
|
|
console.error('请求失败:', error.message)
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 后端接口格式
|
|||
|
|
|
|||
|
|
本模块会调用后端接口 `/webApi/admin-api/ai/tikHup/post_tik_hup`,传递的参数格式为:
|
|||
|
|
|
|||
|
|
```json
|
|||
|
|
{
|
|||
|
|
"interface_type": "8",
|
|||
|
|
"method_type": "GET",
|
|||
|
|
"platform_url": "https://api.tikhub.io/api/v1/douyin/web/fetch_hot_search_result",
|
|||
|
|
"url_params": { "keyword": "测试" }
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 注意事项
|
|||
|
|
|
|||
|
|
1. 所有接口类型必须使用 `InterfaceType` 枚举,不能使用字符串数字
|
|||
|
|
2. HTTP 方法必须使用 `MethodType` 枚举
|
|||
|
|
3. `urlParams` 可以是对象或字符串,取决于实际接口的要求
|
|||
|
|
4. 后端会根据 `interface_type` 从数据库中获取对应的 `platform_token`
|
|||
|
|
|