# TikTok Video Search & Industry Filter (`jaysun/tiktok-video-filter`) Actor

Search TikTok videos by keyword, region, and date, then apply Industry and product-promotion filters.

- **URL**: https://apify.com/jaysun/tiktok-video-filter.md
- **Developed by:** [Jerson Sun](https://apify.com/jaysun) (community)
- **Features:** Limited permissions
- **Stats:** 5 total users, 3 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

### TikTok Video Search & Industry Filter 能做什么？

该 Actor 通过 [TikTok](https://www.tiktok.com/) 关键词搜索获取公开视频数据，并支持国家/地区、发布时间、Industry 行业和“屏蔽产品推荐视频”筛选。它是一个可在 Apify Console、API、计划任务和集成中使用的 TikTok 数据采集与后处理 Actor。

数据获取由 Store Actor [`xmolodtsov/tiktok-search-scraper`](https://apify.com/xmolodtsov/tiktok-search-scraper) 完成；本项目负责输入映射、结果规范化、行业匹配和产品推荐识别。它不绕过私密内容，也不提供 TikTok 官方 API 权限。

### 为什么使用这个 Actor？

- 用一个表单配置关键词、ISO 国家代码和时间范围。
- 使用 `data_xplorer/tiktok-trends` 的 15 个 Industry 分类组织普通搜索结果。
- 通过可解释的规则过滤疑似广告、联盟营销和带货导购视频。
- 在输出中保留匹配分数和命中信号，便于审查误判。
- 可通过 Apify API 调用、定时运行、监控，并导出到常见数据格式或集成服务。

### 筛选条件如何实现？

#### 关键词、国家/地区和时间范围

输入会直接映射到底层 Actor：

| 本 Actor | 底层参数 | 说明 |
|---|---|---|
| `keywords` | `keywords` | 一个或多个 TikTok 搜索词 |
| `countryCode` | `location` | ISO 3166-1 alpha-2 代码，例如 `US`、`GB`、`JP`；是目标搜索地区，不是严格的发布国家过滤 |
| `timeRange` | `dateRange` | 映射为 `ALL`、`YESTERDAY`、`THIS_WEEK`、`THIS_MONTH`、`LAST_3_MONTHS` 或 `LAST_6_MONTHS` |

“过去 24 小时”会映射为底层 TikTok 搜索的 `YESTERDAY`。时间边界由 TikTok 搜索和底层 Actor 解释，因此不是本 Actor 自行计算的严格滚动 24 小时窗口。

底层 Actor 明确说明 `location` 参数不能保证每条结果来自指定国家：TikTok 主要根据请求 IP 选择搜索结果。因此 `countryCode` 仅用于指定目标搜索地区，不能替代严格的作者所在地或视频发布地筛选。

#### Industry 筛选

调研确认：`data_xplorer/tiktok-trends` 的 `industryId` 仅用于趋势 Hashtag，并且其说明明确标注为客户端过滤；普通视频搜索没有可直接复用的 `industryId` 参数。

因此，本 Actor 保留相同的 15 个 ID 和名称，并通过视频描述、标题和 Hashtag 中的行业关键词进行二次匹配。映射位于 `my_actor/industry_taxonomy.json`，可以维护；`additionalIndustryKeywords` 可补充目标语言或市场词汇。

这是启发式分类，不是 TikTok 官方的视频行业标签。默认词表以英文为主，可能出现误判和漏判；提高 `industryMatchThreshold` 会减少误判，但也可能减少结果。

#### 结果排序

`sortBy` 支持发布时间、收藏量、点赞量、播放量和分享量；`sortOrder` 支持正序 `ASC` 与倒序 `DESC`。缺失排序值始终放在结果末尾。

- 发布时间倒序会向底层 Actor 传入 `DATE_POSTED`，优先召回最新视频，再在本地按准确时间倒序。
- 点赞量倒序会向底层 Actor 传入 `MOST_LIKED`，再按实际点赞数倒序。
- 发布时间正序、收藏量、播放量、分享量及其他正序选项使用底层 `RELEVANCE` 召回，再对最多 `maxSourceItems` 条数据排序。
- 填写 `sourceRunId` 时不会重新搜索，只会对该 Run 已有 Dataset 重新排序。

除发布时间倒序和点赞量倒序外，排序仅代表已抓取源数据范围内的顺序，不保证覆盖 TikTok 全站的全局最高或最低结果。增加 `maxSourceItems` 能扩大候选范围，但新抓取可能增加底层 Actor 费用。

#### “屏蔽产品推荐视频”规则

开启 `excludeProductRecommendations` 后，以下信号会累计分数：

- 结构化商品、TikTok Shop、商品锚点、广告或联盟营销字段：3 分。
- 强导购语句，例如 `#tiktokmademebuyit`、`shop now`、`buy now`：3 分。
- `link in bio`、折扣码、优惠券、加入购物车等：2 分。
- `affiliate`、`unboxing`、折扣词或货币价格模式：1 分。

累计分数达到 `productRecommendationThreshold`（默认 3）时，视频被标记为疑似产品推荐；开关开启时不会写入结果数据集。仅出现一个价格通常不会被过滤。输出字段 `productRecommendationScore` 和 `productRecommendationSignals` 可解释判定。

该规则参考 organic-only 的目标，但**不等同于** TikTok Trends 的 `videoOrganicOnly`：后者只用于其 Top Videos 接口，而本项目处理普通关键词搜索结果。

### 可以提取哪些 TikTok 数据？

| 字段 | 类型 | 说明 |
|---|---|---|
| `videoId`, `videoUrl` | string | 视频 ID 与公开页面 URL |
| `description`, `hashtags` | string / array | 视频描述与 Hashtag |
| `publishedAt` | string | 规范化发布时间（源数据提供时） |
| `authorUsername`, `authorName` | string | 公开作者信息 |
| `playCount`, `likeCount`, `commentCount`, `shareCount` | integer | 互动指标 |
| `bookmarkCount` | integer | 收藏量 |
| `industryId`, `industryName`, `industryMatchedSignals` | mixed | 行业选择与匹配依据 |
| `productRecommendationScore`, `productRecommendationSignals` | mixed | 产品推荐判定依据 |
| `rawData` | object | 底层 Actor 原始记录，避免丢失未规范化字段 |

### 如何抓取 TikTok 视频？

1. 在 Actor 输入页填写一个或多个关键词。
2. 选择两位国家/地区代码和发布时间范围。
3. 可选选择 Industry，并按目标语言补充行业关键词。
4. 可选开启“屏蔽产品推荐视频”。
5. 设置最大输出数与最大源视频数，然后运行 Actor。
6. 在 Dataset 查看、筛选或下载结果，在 `SUMMARY` 记录查看各类过滤数量。

### 输入

完整配置请查看 Actor 的 Input 标签页。重要数量设置：

- `maxItems` 是过滤后最多输出多少条。
- `maxSourceItems` 是底层 Actor 最多返回多少条。行业和产品规则在本 Actor 内后处理，因此源条数应高于目标输出数。
- `sortBy` 与 `sortOrder` 控制输出排序；默认按发布时间从新到旧。
- `sourceRunId` 可复用一个已成功完成的底层 Run 及其 Dataset；填写后不会启动新的付费抓取。关键词和筛选配置仍用于本 Actor 的输出标记与后处理。
- `testMode` 仅用于本地无费用测试；开启后不会调用 Store Actor。

### 输出

结果写入默认 Dataset。你可以将 Dataset 下载为 JSON、HTML、CSV 或 Excel 等格式。运行计数写入默认 Key-value store 的 `SUMMARY` 和 `STATE`。

简化示例：

```json
{
  "videoId": "7400000000000000001",
  "videoUrl": "https://www.tiktok.com/@example_creator/video/7400000000000000001",
  "description": "A short science tutorial #education",
  "requestedCountryCode": "US",
  "industryId": "10000000000",
  "industryName": "Education",
  "industryMatchScore": 2,
  "industryMatchedSignals": ["education", "tutorial"],
  "isLikelyProductRecommendation": false,
  "productRecommendationScore": 0,
  "sourceActor": "xmolodtsov/tiktok-search-scraper"
}
```

### 本地测试

项目自带的 `example_input.json` 已开启 `testMode`，因此以下命令不会调用付费 Store Actor。项目使用 Python 3.14；可用 `uv` 创建隔离环境：

```powershell
uv python install 3.14
uv venv --python 3.14 .venv
uv pip install --python .venv\Scripts\python.exe -r requirements.txt
$env:PATH = "$PWD\.venv\Scripts;$env:PATH"
apify run --input-file example_input.json --user-agent apify-agent-skills/apify-actor-development
```

在 macOS 或 Linux 上，将虚拟环境路径改为 `.venv/bin`。

关闭 `testMode` 后进行真实抓取，需要通过 `apify login` 登录，或在环境变量中提供 `APIFY_TOKEN`。令牌不要写入项目文件或日志。

### 抓取 TikTok 的费用是多少？

本 Actor 自身消耗运行计算资源；真实模式还会调用 `xmolodtsov/tiktok-search-scraper`，其收费以 Apify Store 当前页面为准。当前基础视频结果采用按条收费；本项目显式关闭 expansion、评论、作者画像、转录和视频下载等可选附加项。因为 Industry 与产品推荐规则是获取数据后的过滤，被过滤的源视频仍可能产生底层 Actor 费用。使用 `maxSourceItems` 控制最大来源条数，并先用较小输入验证结果质量。

底层 Actor 当前对 Apify Free 计划设置每次最多 100 条、每个自然月最多 20 次运行的限制；付费计划通常解除这些开发者限制。价格和计划规则可能变化，请以其 Store Pricing 页面为准。

### 已知限制与建议

- TikTok 与底层 Actor 的字段结构可能变化；规范化字段缺失时会为 `null`，完整记录仍保存在 `rawData`。
- `countryCode` 只映射到目标搜索地区；TikTok 主要按请求 IP 返回结果，不保证视频作者或发布地点属于该国家。
- Industry 是关键词/Hashtag 启发式分类，尤其对非英文内容需要补充行业词。
- 产品推荐规则无法识别所有软性植入，也可能把真实测评判断为产品推荐。
- 遵守 TikTok 服务条款、robots 规则以及适用的隐私、版权和数据保护法律。

### FAQ、免责声明与支持

本 Actor 只处理用户公开分享的数据，不以提取私人邮箱、性别或精确位置为目标。不过，公开结果仍可能包含受 GDPR 或其他地区法律保护的个人数据。只有在具有合法理由时才应处理个人数据；如不确定，请咨询法律顾问。

真实运行失败时，先确认 Apify 登录/令牌、底层 Actor 可用性与账户额度，然后查看运行日志和 `STATE`。如需编程调用，请使用 Actor 的 API 标签页；问题和改进建议可通过 Actor 的 Issues 标签页提交。

# Actor input Schema

## `keywords` (type: `array`):

要在 TikTok 中搜索的一个或多个关键词。底层 Actor 的 keywords 参数会直接使用这些值。

## `countryCode` (type: `string`):

ISO 3166-1 alpha-2 两位地区代码，例如 US、GB、JP。将映射到底层 Actor 的 location 参数；TikTok 仍主要按请求 IP 决定结果，因此它不是严格的发布国家过滤。

## `timeRange` (type: `string`):

TikTok 搜索的发布时间范围。将映射到底层 Actor 的 dateRange 参数；具体边界遵循 TikTok 搜索语义。

## `sortBy` (type: `string`):

选择过滤后结果的排序指标。发布时间倒序和点赞量倒序会同时映射到底层 Actor；其他选项在最多 maxSourceItems 条源数据中进行本地排序。

## `sortOrder` (type: `string`):

ASC 为从小到大或从旧到新；DESC 为从大到小或从新到旧。缺失排序值始终排在最后。

## `industryId` (type: `string`):

参考 data_xplorer/tiktok-trends 的 Industry ID。普通视频搜索不支持该 ID，因此本 Actor 使用描述和 Hashtag 关键词进行二次过滤。

## `additionalIndustryKeywords` (type: `array`):

可选。添加适合目标市场或语言的行业词，以降低默认英文映射的漏判。

## `excludeProductRecommendations` (type: `boolean`):

开启后，过滤含商品锚点、TikTok Shop、联盟营销、导购词、折扣码或价格组合信号的疑似带货视频。

## `maxItems` (type: `integer`):

过滤后最多写入结果数据集的视频数量。

## `maxSourceItems` (type: `integer`):

最多向底层 Actor 请求的视频数。后处理会丢弃部分结果，因此该值通常应大于最大输出数；底层 Actor 可能按返回结果收费。

## `sourceRunId` (type: `string`):

可选。填写一个已成功运行的 xmolodtsov/tiktok-search-scraper Run ID，直接读取其 Dataset，不再启动新的付费抓取。留空时正常启动新 Run。

## `industryMatchThreshold` (type: `integer`):

视频至少命中多少个行业关键词才保留。提高该值可减少误判，但会增加漏判。

## `productRecommendationThreshold` (type: `integer`):

产品推荐信号的累计分数达到该阈值时判定为疑似带货。默认 3；结构化商品字段本身计 3 分。

## `testMode` (type: `boolean`):

仅用于无令牌、无费用的本地冒烟测试。开启后使用内置样例，不调用 TikTok 底层 Actor。

## Actor input object example

```json
{
  "keywords": [
    "artificial intelligence"
  ],
  "countryCode": "US",
  "timeRange": "PAST_WEEK",
  "sortBy": "publishedAt",
  "sortOrder": "DESC",
  "industryId": "",
  "additionalIndustryKeywords": [],
  "excludeProductRecommendations": false,
  "maxItems": 10,
  "maxSourceItems": 20,
  "sourceRunId": "",
  "industryMatchThreshold": 1,
  "productRecommendationThreshold": 3,
  "testMode": false
}
```

# Actor output Schema

## `results` (type: `string`):

Dataset containing normalized TikTok video records that passed all enabled filters.

## `summary` (type: `string`):

Counts of source, output, duplicate, invalid, Industry-filtered, and product-filtered items.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "keywords": [
        "artificial intelligence"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("jaysun/tiktok-video-filter").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "keywords": ["artificial intelligence"] }

# Run the Actor and wait for it to finish
run = client.actor("jaysun/tiktok-video-filter").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "keywords": [
    "artificial intelligence"
  ]
}' |
apify call jaysun/tiktok-video-filter --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,jaysun/tiktok-video-filter"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/8z2fWMOSSToPAUbcN/builds/GDdF7mOgiwoubLzDf/openapi.json
