From 9bcbb48d5472d4fa5781df6344e4f2baed94e45a Mon Sep 17 00:00:00 2001 From: satoru Date: Sun, 22 Dec 2024 19:37:55 +0900 Subject: [PATCH 1/4] add:msg --- TikTokApi/tiktok.py | 1 + 1 file changed, 1 insertion(+) diff --git a/TikTokApi/tiktok.py b/TikTokApi/tiktok.py index 23c2e604..211a7dd1 100644 --- a/TikTokApi/tiktok.py +++ b/TikTokApi/tiktok.py @@ -216,6 +216,7 @@ async def create_sessions( executable_path: str = None ): """ + Its MIneeeeeeeeeeeeee Create sessions for use within the TikTokApi class. These sessions are what will carry out requesting your data from TikTok. From 541b14dc60fd64c7eb595849eb511ccec61b23bc Mon Sep 17 00:00:00 2001 From: satoru Date: Sun, 22 Dec 2024 22:20:58 +0900 Subject: [PATCH 2/4] add:anything --- TikTokApi/api/search.py | 27 +++++++++++++++++++++++++++ TikTokApi/tiktok.py | 14 +++++--------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/TikTokApi/api/search.py b/TikTokApi/api/search.py index e9118e36..6b2dcdb3 100644 --- a/TikTokApi/api/search.py +++ b/TikTokApi/api/search.py @@ -41,6 +41,33 @@ async def users(search_term, count=10, cursor=0, **kwargs) -> Iterator[User]: ): yield user + @staticmethod + async def general_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/full/", + params=params, + headers=kwargs.get("headers"), + session_index=kwargs.get("session_index"), + ) + if resp is None: + raise InvalidResponseException( + resp, "TikTok returned an invalid response." + ) + + if not resp.get("has_more", False): + return + cursor = resp.get("cursor") + + return resp + + @staticmethod async def search_type( search_term, obj_type, count=10, cursor=0, **kwargs diff --git a/TikTokApi/tiktok.py b/TikTokApi/tiktok.py index 211a7dd1..b3e1c3e3 100644 --- a/TikTokApi/tiktok.py +++ b/TikTokApi/tiktok.py @@ -91,18 +91,14 @@ def __create_logger(self, name: str, level: int = logging.DEBUG): async def __set_session_params(self, session: TikTokPlaywrightSession): """Set the session params for a TikTokPlaywrightSession""" - user_agent = await session.page.evaluate("() => navigator.userAgent") - language = await session.page.evaluate( - "() => navigator.language || navigator.userLanguage" - ) - platform = await session.page.evaluate("() => navigator.platform") + user_agent = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36" + language = "ja-JP" + platform = "web_pc" device_id = str(random.randint(10**18, 10**19 - 1)) # Random device id history_len = str(random.randint(1, 10)) # Random history length screen_height = str(random.randint(600, 1080)) # Random screen height screen_width = str(random.randint(800, 1920)) # Random screen width - timezone = await session.page.evaluate( - "() => Intl.DateTimeFormat().resolvedOptions().timeZone" - ) + timezone = "Asia/Tokyo" session_params = { "aid": "1988", @@ -207,7 +203,7 @@ async def create_sessions( ms_tokens: list[str] = None, proxies: list = None, sleep_after=1, - starting_url="https://www.tiktok.com", + starting_url="https://www.tiktok.com/@test", context_options: dict = {}, override_browser_args: list[dict] = None, cookies: list[dict] = None, From 8e6f2fca35a8ca8bd4f66a43d858cc2f618d6360 Mon Sep 17 00:00:00 2001 From: satoru Date: Sun, 22 Dec 2024 22:42:53 +0900 Subject: [PATCH 3/4] change:start_url --- TikTokApi/tiktok.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TikTokApi/tiktok.py b/TikTokApi/tiktok.py index b3e1c3e3..e91a123e 100644 --- a/TikTokApi/tiktok.py +++ b/TikTokApi/tiktok.py @@ -203,7 +203,7 @@ async def create_sessions( ms_tokens: list[str] = None, proxies: list = None, sleep_after=1, - starting_url="https://www.tiktok.com/@test", + starting_url="https://www.tiktok.com/login", context_options: dict = {}, override_browser_args: list[dict] = None, cookies: list[dict] = None, From f6c33835422860ad8714a35afa192c06408999f2 Mon Sep 17 00:00:00 2001 From: satoru Date: Mon, 23 Dec 2024 19:10:59 +0900 Subject: [PATCH 4/4] add:search_preview --- TikTokApi/api/search.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/TikTokApi/api/search.py b/TikTokApi/api/search.py index 6b2dcdb3..6d86b618 100644 --- a/TikTokApi/api/search.py +++ b/TikTokApi/api/search.py @@ -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