# Query Douyin videos and accounts with Python

Query Douyin videos and accounts with Python. Follow concrete contracts, examples and reviewable steps using Douyin.

Canonical page: https://datanavoapi.com/en/guides/douyin-api-python/

This is a local simulation. Program-generated samples are not live platform data and do not establish provider availability.

## Task goal

Query Douyin videos and accounts with Python. Follow concrete contracts, examples and reviewable steps using Douyin.

This is a local simulation. Program-generated samples are not live platform data and do not establish provider availability.

## Inputs, goal and deliverable

Query Douyin videos and accounts with Python. Follow concrete contracts, examples and reviewable steps using Douyin.

Inputs consist of explicit platforms, keywords or object identifiers. Preserve the samples, request IDs, classifications and unresolved questions in the deliverable. The task does not schedule itself or paginate indefinitely.

## Step-by-step plan

| Step | Capability | Input | Output |

| --- | --- | --- | --- |

| 1 | douyin.videos.search | query, sort | post / items |

| 2 | douyin.videos.get | id | post / item |

| 3 | douyin.users.get | id | account / item |

- [Douyin video search](https://datanavoapi.com/en/apis/douyin/videos/search/)
- [Douyin video detail](https://datanavoapi.com/en/apis/douyin/videos/get/)
- [Douyin user profile](https://datanavoapi.com/en/apis/douyin/users/get/)

## Reusable task prompt

Ask the client to present a plan before you confirm each execution. This prompt bounds the sample; it does not call an external service for you.

```text
Goal: Query Douyin videos and accounts with Python
Use only DataNavoAPI local demo/simulated mode.
Planned capabilities: douyin.videos.search → douyin.videos.get → douyin.users.get
Describe inputs and output fields and propose a bounded request count first.
Execute explicitly, retaining request IDs. Stop on failures or unknown outcomes.
Return a table, missing fields and sampling limits; never present fictional samples as market facts.
```

## Plan, run and export

This bounded example has 3 steps. Successful customer simulation costs 5 TEST; anonymous demo costs zero. Provide each required identifier before generating a fixed plan; search results do not expand the request list automatically.

Use data.items[].id for the matching platform and object detail, account IDs for account content and comment IDs for replies. Check object types before reusing an ID. Fixture IDs do not establish a real relationship. The workbench exports per-step JSON and source-labelled CSV.

| Workbench field | Meaning | Example |

| --- | --- | --- |

| query | 研究关键词 | 户外咖啡 |

| step2_id | 步骤 2 · id | 7694940173372575014 |

| step3_id | 步骤 3 · id | MS4wLjABAAAAZ0aPDJzFhBrs0q3wVsp2a9WWrBuAUMsVyygoaO0bCw8 |

```json
{
  "schemaVersion": 1,
  "templateId": "guide-douyin-api-python",
  "runId": "00000000-0000-4000-8000-000000000001",
  "inputs": {
    "query": "户外咖啡",
    "step2_id": "7694940173372575014",
    "step3_id": "MS4wLjABAAAAZ0aPDJzFhBrs0q3wVsp2a9WWrBuAUMsVyygoaO0bCw8"
  },
  "maxTotalCredits": 5,
  "estimatedCredits": 5,
  "priceVersion": "test-credit-v1",
  "steps": [
    {
      "id": "step-1",
      "title": "搜索抖音视频",
      "capability": "douyin.videos.search",
      "params": {
        "query": "户外咖啡",
        "sort": "relevance"
      },
      "maxCredits": 2,
      "idempotencyKey": "wf:00000000-0000-4000-8000-000000000001:step-1"
    },
    {
      "id": "step-2",
      "title": "抖音视频详情",
      "capability": "douyin.videos.get",
      "params": {
        "id": "7694940173372575014"
      },
      "maxCredits": 2,
      "idempotencyKey": "wf:00000000-0000-4000-8000-000000000001:step-2"
    },
    {
      "id": "step-3",
      "title": "获取抖音账号资料",
      "capability": "douyin.users.get",
      "params": {
        "id": "MS4wLjABAAAAZ0aPDJzFhBrs0q3wVsp2a9WWrBuAUMsVyygoaO0bCw8"
      },
      "maxCredits": 1,
      "idempotencyKey": "wf:00000000-0000-4000-8000-000000000001:step-3"
    }
  ]
}
```

- [Open this task in the workbench](https://datanavoapi.com/tools/workflow-runner/?template=guide-douyin-api-python)
- [Download Skill instructions](https://datanavoapi.com/downloads/skills/guide-douyin-api-python.md)

## Review and stop conditions

- Each conclusion links back to a sample and request ID.
- Pagination stops at the agreed bound.
- Missing fields remain missing rather than being invented by the model.
- External writes, scheduled monitoring and automatic top-ups are not enabled by this workflow.

## Python bounded-task example

By default this prints the complete plan without network access. Add --execute-demo to run these fixed samples and export source-labelled JSON. Any failure stops execution; no automatic paging or request expansion occurs.

```python
import json
import sys
from urllib.request import ProxyHandler, Request, build_opener

steps = json.loads("[{\"capability\":\"douyin.videos.search\",\"method\":\"GET\",\"params\":{\"query\":\"户外咖啡\",\"sort\":\"relevance\"}},{\"capability\":\"douyin.videos.get\",\"method\":\"GET\",\"params\":{\"id\":\"7694940173372575014\"}},{\"capability\":\"douyin.users.get\",\"method\":\"GET\",\"params\":{\"id\":\"MS4wLjABAAAAZ0aPDJzFhBrs0q3wVsp2a9WWrBuAUMsVyygoaO0bCw8\"}}]")
# Preview only by default. Run with --execute-demo to request this fixed demo sample.
print(json.dumps(steps, ensure_ascii=False, indent=2))
if sys.argv[1:] != ["--execute-demo"]:
    raise SystemExit("Preview only. No request was sent.")
opener = build_opener(ProxyHandler({}))
results = []
for step in steps:
    request = Request("https://datanavoapi.com/api/atlas-demo",
        data=json.dumps(step).encode(), method="POST",
        headers={"Content-Type": "application/json", "Origin": "https://datanavoapi.com"})
    with opener.open(request, timeout=10) as response:
        result = json.load(response)
    if result.get("meta", {}).get("mode") != "demo" or result.get("meta", {}).get("billing", {}).get("charged"):
        raise RuntimeError("Unexpected response; stop without retrying")
    results.append({"capability": step["capability"], "response": result})
# No fan-out, automatic paging or retries. Export retains each source contract.
with open("datanavo-task-results.json", "w", encoding="utf-8") as output:
    json.dump(results, output, ensure_ascii=False, indent=2)
print("Saved datanavo-task-results.json")
```

## Related pages

- [Douyin video search](https://datanavoapi.com/en/apis/douyin/videos/search/)
- [Douyin video detail](https://datanavoapi.com/en/apis/douyin/videos/get/)
- [Douyin user profile](https://datanavoapi.com/en/apis/douyin/users/get/)
- [Douyin APIs](https://datanavoapi.com/en/apis/douyin/)
- [Douyin MCP](https://datanavoapi.com/en/mcp/douyin/)
- [Post fields](https://datanavoapi.com/en/docs/objects/post/)
- [How can AI assist an account review?](https://datanavoapi.com/en/answers/ai-account-audit-and-review/)
- [How do I choose data sources for a sentiment workflow?](https://datanavoapi.com/en/answers/bettafish-data-source/)
- [How do I connect Chinese social platforms through one MCP workflow?](https://datanavoapi.com/en/answers/china-social-data-mcp/)
- [How can public social data support research?](https://datanavoapi.com/en/answers/chinese-social-media-alternative-data/)

[中文](https://datanavoapi.com/guides/douyin-api-python/)
