From 7f035b35f071bcb59c96d98af627ca089cb0dc42 Mon Sep 17 00:00:00 2001 From: Huzaifa Date: Tue, 16 Jul 2024 11:07:11 +0100 Subject: [PATCH 1/2] modifies client.py and streams.py to use v1.3 of the TikTok Business API --- tap_tiktok_business/client.py | 26 +++++++++++++++++++++----- tap_tiktok_business/streams.py | 10 +++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/tap_tiktok_business/client.py b/tap_tiktok_business/client.py index e3e62c9..1e2fd9a 100644 --- a/tap_tiktok_business/client.py +++ b/tap_tiktok_business/client.py @@ -19,7 +19,7 @@ class TapTiktokBusinessStream(RESTStream): """TapTiktokBusinessStream stream class.""" records_jsonpath = "$[*]" - url_base = "https://business-api.tiktok.com/open_api/v1.2/business" + url_base = "https://business-api.tiktok.com/open_api/v1.3/business" fields = None # Account and Video streams will use this @property @@ -59,14 +59,30 @@ def get_url_params( self, context: Optional[dict], next_page_token: Optional[Any] = None ) -> Dict[str, Any]: """Return a dictionary of values to be used in URL parameterization. - params like business id and fields are actually added in the - prepare_request_payload method due to the idiosyncrasies of the - tiktok api. + + Args: + context: The stream context. + next_page_token: The next page index or value. + + Returns: + A dictionary of URL query parameters. """ - params: Dict = super().get_url_params(context, next_page_token) + params: dict = {} + if self.name == "VideosStream": + fields = [ + "item_id", "create_time", "thumbnail_url", "share_url", "embed_url", + "caption", "video_views", "likes", "comments", "shares", "reach", + "video_duration", "full_video_watched_rate", "total_time_watched", + "average_time_watched", "impression_sources", "audience_countries" + ] + params["fields"] = ",".join(fields) + if next_page_token: + params["page"] = next_page_token if self.replication_key: params["sort"] = "asc" params["order_by"] = self.replication_key + if context and "business_id" in context: + params["business_id"] = context["business_id"] return params def request_records(self, context: Optional[dict]) -> Iterable[dict]: diff --git a/tap_tiktok_business/streams.py b/tap_tiktok_business/streams.py index 6952edc..96dc355 100644 --- a/tap_tiktok_business/streams.py +++ b/tap_tiktok_business/streams.py @@ -21,7 +21,7 @@ class AccountsStream(TapTiktokBusinessStream): primary_keys = ["business_id"] replication_key = None schema_filepath = SCHEMAS_DIR / "accounts.schema.json" - rest_method = "POST" + rest_method = "GET" fields = [ "username", "display_name", @@ -52,11 +52,11 @@ class VideosStream(TapTiktokBusinessStream): """Define custom stream.""" name = "videos" - path = "/videos/list/" + path = "/video/list/" parent_stream_type = AccountsStream primary_keys = ["item_id"] replication_key = "create_time" - rest_method = "POST" + rest_method = "GET" fields = [ "item_id", "create_time", @@ -97,11 +97,11 @@ class CommentsStream(TapTiktokBusinessStream): """Define custom stream.""" name = "comments" - path = "/comments/list/" + path = "/comment/list/" parent_stream_type = VideosStream primary_keys = ["comment_id"] replication_key = "create_time" - rest_method = "POST" + rest_method = "GET" schema_filepath = SCHEMAS_DIR / "comments.schema.json" def prepare_request_payload( From a583bdd2d9d219609127a0cdfba9378f09db4e73 Mon Sep 17 00:00:00 2001 From: Huzaifa Date: Tue, 16 Jul 2024 11:11:16 +0100 Subject: [PATCH 2/2] updated to make pull request --- tap_tiktok_business/streams.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tap_tiktok_business/streams.py b/tap_tiktok_business/streams.py index 96dc355..2365cb0 100644 --- a/tap_tiktok_business/streams.py +++ b/tap_tiktok_business/streams.py @@ -120,7 +120,7 @@ def prepare_request_payload( payload["cursor"] = next_page_token return payload - + def parse_response( self, response: requests.Response, context: Optional[dict] ) -> Iterable[dict]: