Skip to content

Commit

Permalink
add:search_preview
Browse files Browse the repository at this point in the history
  • Loading branch information
PTK1182 committed Dec 23, 2024
1 parent 8e6f2fc commit f6c3383
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions TikTokApi/api/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,32 @@ async def general_search(search_term,cursor=0,**kwargs):
resp, "TikTok returned an invalid response."
)

if not resp.get("has_more", False):
return
cursor = resp.get("cursor")

return resp

@staticmethod
async def preview_search(search_term,cursor=0,**kwargs):

params = {
"keyword": search_term,
"cursor": cursor,
"from_page": "search",
"web_search_code": """{"tiktok":{"client_params_x":{"search_engine":{"ies_mt_user_live_video_card_use_libra":1,"mt_search_general_user_live_card":1}},"search_server":{}}}""",
}
resp = await Search.parent.make_request(
url=f"https://www.tiktok.com/api/search/general/preview/",
params=params,
headers=kwargs.get("headers"),
session_index=kwargs.get("session_index"),
)
if resp is None:
raise InvalidResponseException(
resp, "TikTok returned an invalid response."
)


return resp

@staticmethod
async def search_type(
search_term, obj_type, count=10, cursor=0, **kwargs
Expand Down

0 comments on commit f6c3383

Please sign in to comment.