Skip to content

Commit

Permalink
Merge pull request #4 from chartica/v1.3
Browse files Browse the repository at this point in the history
V1.3
  • Loading branch information
hkuffel authored Aug 28, 2024
2 parents d77e27e + a583bdd commit c912d91
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
26 changes: 21 additions & 5 deletions tap_tiktok_business/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]:
Expand Down
12 changes: 6 additions & 6 deletions tap_tiktok_business/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand All @@ -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]:
Expand Down

0 comments on commit c912d91

Please sign in to comment.