Skip to content

Commit

Permalink
docs: add video query information
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandreteles committed Sep 24, 2024
1 parent 07529bb commit 08c7b3e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
TikTok is a Python library for interacting with the TikTok Research API.

This library provides a simple and efficient way to access TikTok's API endpoints,
allowing developers to retrieve user information, video details, and other data.
allowing developers to retrieve user information, video details, and other relevant data.

TikTok is built on top of the `httpx` library, which is a powerful and flexible HTTP library,
and uses `orjson` for efficient JSON serialization and deserialization.
Expand Down Expand Up @@ -50,3 +50,38 @@ query = Query(auth)

print(user_info)
```

Given the complexity of video queries, this library provides a helper class to build them.
It introduces some level of indirection and API inconsistency, but its introduction was a deliberate design choice to help users create queries
that are easy to understand and modify without the need to manually write the JSON object or learn a dedicated DSL.

```python
# Example: Build a query to search for videos uploaded by "example_username" between August 1st and August 2nd, 2024.
from TikTok.Query import Query
from TikTok.ValidationModels.Video import (
VideoQueryRequestBuilder,
VideoQueryOperation,
VideoQueryFieldName,
VideoRegionCode,
VideoQueryFields,
)

query = Query(auth)

video_query = VideoQueryRequestBuilder()

request = (
video_query.start_date("20240801")
.end_date("20240802")
.max_count(100)
.and_(VideoQueryOperation.EQ, VideoQueryFieldName.username, ["example_username"])
.build()
)

video_query_response = await query.video.search(
request=request, fields=[VideoQueryFields.id, VideoQueryFields.voice_to_text]
)

```

If you are interested in learning more about the underlying API, you can find the documentation here: [https://developers.tiktok.com/doc/research-api-specs-query-videos](https://developers.tiktok.com/doc/research-api-specs-query-videos)
36 changes: 36 additions & 0 deletions TikTok/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,40 @@
print(user_info)
```
Given the complexity of video queries, this library provides a helper class to build them.
It introduces some level of indirection and API inconsistency, but its introduction was a deliberate design choice to help users create queries
that are easy to understand and modify without the need to manually write the JSON object or learn a dedicated DSL.
```python
# Example: Build a query to search for videos uploaded by "example_username" between August 1st and August 2nd, 2024.
from TikTok.Query import Query
from TikTok.ValidationModels.Video import (
VideoQueryRequestBuilder,
VideoQueryOperation,
VideoQueryFieldName,
VideoRegionCode,
VideoQueryFields,
)
query = Query(auth)
video_query = VideoQueryRequestBuilder()
request = (
video_query.start_date("20240801")
.end_date("20240802")
.max_count(100)
.and_(VideoQueryOperation.EQ, VideoQueryFieldName.username, ["example_username"])
.build()
)
video_query_response = await query.video.search(
request=request, fields=[VideoQueryFields.id, VideoQueryFields.voice_to_text]
)
```
If you are interested in learning more about the underlying API, you can find the documentation here: [https://developers.tiktok.com/doc/research-api-specs-query-videos](https://developers.tiktok.com/doc/research-api-specs-query-videos)
"""

0 comments on commit 08c7b3e

Please sign in to comment.