Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file.

## [0.1.10](https://github.com/sns-sdks/python-tiktok/v0.1.10) (2024-12-16)

### Features

- Add api for get account post privacy setting
- Add api for get post publish status
- fix fields type in get data.

## [0.1.9](https://github.com/sns-sdks/python-tiktok/v0.1.9) (2024-08-07)

### Features
Expand Down Expand Up @@ -35,7 +43,7 @@ All notable changes to this project will be documented in this file.

### Fix

- fix sometimes the `requests` module raise the `JSONDecodeError not found`.
- fix sometimes the `requests` module raise the `JSONDecodeError not found`.

## [0.1.4](https://github.com/sns-sdks/python-tiktok/v0.1.4) (2022-08-23)

Expand Down
53 changes: 51 additions & 2 deletions pytiktok/business_account_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Core API impl.
"""

import json
from typing import Optional, List, Union

import requests
Expand Down Expand Up @@ -40,6 +41,12 @@
# Must be the same as the TikTok account holder redirect URL set in the app.
self.oauth_redirect_uri = oauth_redirect_uri

@staticmethod
def _format_fields(fields):
if isinstance(fields, str):
return fields
return json.dumps(fields)

Check warning on line 48 in pytiktok/business_account_api.py

View check run for this annotation

Codecov / codecov/patch

pytiktok/business_account_api.py#L46-L48

Added lines #L46 - L48 were not covered by tests

def generate_access_token(
self, code: str, redirect_uri: Optional[str] = None, return_json: bool = False
) -> Union[mds.BusinessAccessToken, dict]:
Expand Down Expand Up @@ -235,7 +242,7 @@
if end_date is not None:
params["end_date"] = end_date
if fields is not None:
params["fields"] = fields
params["fields"] = self._format_fields(fields)

Check warning on line 245 in pytiktok/business_account_api.py

View check run for this annotation

Codecov / codecov/patch

pytiktok/business_account_api.py#L245

Added line #L245 was not covered by tests

resp = self._request(path="business/get/", params=params)
data = self.parse_response(resp)
Expand Down Expand Up @@ -268,7 +275,7 @@

params = {"business_id": business_id}
if fields is not None:
params["fields"] = fields
params["fields"] = self._format_fields(fields)

Check warning on line 278 in pytiktok/business_account_api.py

View check run for this annotation

Codecov / codecov/patch

pytiktok/business_account_api.py#L278

Added line #L278 was not covered by tests
if filters is not None:
params["filters"] = filters
if cursor is not None:
Expand All @@ -284,6 +291,26 @@
data if return_json else mds.BusinessVideosResponse.new_from_json_dict(data)
)

def get_account_post_privacy(
self,
business_id: str,
return_json: bool = False,
) -> Union[mds.BusinessAccountPrivacySettingResponse, dict]:
"""
Get the post privacy settings of a TikTok account.
:param business_id: Application specific unique identifier for the TikTok account.
:param return_json: Type for returned data. If you set True JSON data will be returned.
:return: Account's post privacy setting
"""
params = {"business_id": business_id}
resp = self._request(path="business/video/settings/", params=params)
data = self.parse_response(resp)
return (

Check warning on line 308 in pytiktok/business_account_api.py

View check run for this annotation

Codecov / codecov/patch

pytiktok/business_account_api.py#L305-L308

Added lines #L305 - L308 were not covered by tests
data
if return_json
else mds.BusinessAccountPrivacySettingResponse.new_from_json_dict(data)
)

def create_video(
self,
business_id: str,
Expand Down Expand Up @@ -351,6 +378,28 @@
else mds.BusinessPhotoPublishResponse.new_from_json_dict(data)
)

def get_publish_status(
self,
business_id: str,
publish_id: str,
return_json: bool = False,
) -> Union[mds.BusinessPublishStatusResponse, dict]:
"""
Get the publishing status of a TikTok video post or photo post.
:param business_id: Application specific unique identifier for the TikTok account.
:param publish_id: Unique identifier for a post publishing task. Value of the `share_id`.
:param return_json: Type for returned data. If you set True JSON data will be returned.
:return: publish status
"""
params = {"business_id": business_id, "publish_id": publish_id}
resp = self._request(path="business/publish/status/", params=params)
data = self.parse_response(resp)
return (

Check warning on line 397 in pytiktok/business_account_api.py

View check run for this annotation

Codecov / codecov/patch

pytiktok/business_account_api.py#L394-L397

Added lines #L394 - L397 were not covered by tests
data
if return_json
else mds.BusinessPublishStatusResponse.new_from_json_dict(data)
)

def get_video_comments(
self,
business_id: str,
Expand Down
26 changes: 26 additions & 0 deletions pytiktok/models/business_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ class BusinessAccountResponse(BusinessBaseResponse):
data: Optional[BusinessAccount] = field(default=None)


@dataclass
class BusinessAccountPrivacySetting(BaseModel):
privacy_level_options: Optional[List[str]] = field(default=None)
comment_disabled: Optional[bool] = field(default=None)
duet_disabled: Optional[bool] = field(default=None)
stitch_disabled: Optional[bool] = field(default=None)
max_video_post_duration_sec: Optional[int] = field(default=None)


@dataclass
class BusinessAccountPrivacySettingResponse(BusinessBaseResponse):
data: Optional[BusinessAccountPrivacySetting] = field(default=None)


@dataclass
class BusinessVideoImpressionSource(BaseModel):
impression_source: Optional[str] = field(default=None)
Expand Down Expand Up @@ -192,6 +206,18 @@ class BusinessPhotoPublishResponse(BusinessBaseResponse):
data: Optional[BusinessPhotoPublish] = field(default=None)


@dataclass
class BusinessPublishStatus(BaseModel):
status: Optional[str] = field(default=None)
post_ids: Optional[List[str]] = field(default=None)
reason: Optional[str] = field(default=None)


@dataclass
class BusinessPublishStatusResponse(BusinessBaseResponse):
data: Optional[BusinessPublishStatus] = field(default=None)


@dataclass
class BusinessComment(BaseModel):
"""
Expand Down
Loading