Skip to content

Commit 2e39677

Browse files
authored
Merge pull request #22 from MerleLiuKun/main
[API] new api support
2 parents b2a242e + 4790dec commit 2e39677

File tree

3 files changed

+86
-3
lines changed

3 files changed

+86
-3
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

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

5+
## [0.1.10](https://github.com/sns-sdks/python-tiktok/v0.1.10) (2024-12-16)
6+
7+
### Features
8+
9+
- Add api for get account post privacy setting
10+
- Add api for get post publish status
11+
- fix fields type in get data.
12+
513
## [0.1.9](https://github.com/sns-sdks/python-tiktok/v0.1.9) (2024-08-07)
614

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

3644
### Fix
3745

38-
- fix sometimes the `requests` module raise the `JSONDecodeError not found`.
46+
- fix sometimes the `requests` module raise the `JSONDecodeError not found`.
3947

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

pytiktok/business_account_api.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Core API impl.
33
"""
44

5+
import json
56
from typing import Optional, List, Union
67

78
import requests
@@ -40,6 +41,12 @@ def __init__(
4041
# Must be the same as the TikTok account holder redirect URL set in the app.
4142
self.oauth_redirect_uri = oauth_redirect_uri
4243

44+
@staticmethod
45+
def _format_fields(fields):
46+
if isinstance(fields, str):
47+
return fields
48+
return json.dumps(fields)
49+
4350
def generate_access_token(
4451
self, code: str, redirect_uri: Optional[str] = None, return_json: bool = False
4552
) -> Union[mds.BusinessAccessToken, dict]:
@@ -235,7 +242,7 @@ def get_account_data(
235242
if end_date is not None:
236243
params["end_date"] = end_date
237244
if fields is not None:
238-
params["fields"] = fields
245+
params["fields"] = self._format_fields(fields)
239246

240247
resp = self._request(path="business/get/", params=params)
241248
data = self.parse_response(resp)
@@ -268,7 +275,7 @@ def get_account_videos(
268275

269276
params = {"business_id": business_id}
270277
if fields is not None:
271-
params["fields"] = fields
278+
params["fields"] = self._format_fields(fields)
272279
if filters is not None:
273280
params["filters"] = filters
274281
if cursor is not None:
@@ -284,6 +291,26 @@ def get_account_videos(
284291
data if return_json else mds.BusinessVideosResponse.new_from_json_dict(data)
285292
)
286293

294+
def get_account_post_privacy(
295+
self,
296+
business_id: str,
297+
return_json: bool = False,
298+
) -> Union[mds.BusinessAccountPrivacySettingResponse, dict]:
299+
"""
300+
Get the post privacy settings of a TikTok account.
301+
:param business_id: Application specific unique identifier for the TikTok account.
302+
:param return_json: Type for returned data. If you set True JSON data will be returned.
303+
:return: Account's post privacy setting
304+
"""
305+
params = {"business_id": business_id}
306+
resp = self._request(path="business/video/settings/", params=params)
307+
data = self.parse_response(resp)
308+
return (
309+
data
310+
if return_json
311+
else mds.BusinessAccountPrivacySettingResponse.new_from_json_dict(data)
312+
)
313+
287314
def create_video(
288315
self,
289316
business_id: str,
@@ -351,6 +378,28 @@ def create_photo(
351378
else mds.BusinessPhotoPublishResponse.new_from_json_dict(data)
352379
)
353380

381+
def get_publish_status(
382+
self,
383+
business_id: str,
384+
publish_id: str,
385+
return_json: bool = False,
386+
) -> Union[mds.BusinessPublishStatusResponse, dict]:
387+
"""
388+
Get the publishing status of a TikTok video post or photo post.
389+
:param business_id: Application specific unique identifier for the TikTok account.
390+
:param publish_id: Unique identifier for a post publishing task. Value of the `share_id`.
391+
:param return_json: Type for returned data. If you set True JSON data will be returned.
392+
:return: publish status
393+
"""
394+
params = {"business_id": business_id, "publish_id": publish_id}
395+
resp = self._request(path="business/publish/status/", params=params)
396+
data = self.parse_response(resp)
397+
return (
398+
data
399+
if return_json
400+
else mds.BusinessPublishStatusResponse.new_from_json_dict(data)
401+
)
402+
354403
def get_video_comments(
355404
self,
356405
business_id: str,

pytiktok/models/business_account.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,20 @@ class BusinessAccountResponse(BusinessBaseResponse):
111111
data: Optional[BusinessAccount] = field(default=None)
112112

113113

114+
@dataclass
115+
class BusinessAccountPrivacySetting(BaseModel):
116+
privacy_level_options: Optional[List[str]] = field(default=None)
117+
comment_disabled: Optional[bool] = field(default=None)
118+
duet_disabled: Optional[bool] = field(default=None)
119+
stitch_disabled: Optional[bool] = field(default=None)
120+
max_video_post_duration_sec: Optional[int] = field(default=None)
121+
122+
123+
@dataclass
124+
class BusinessAccountPrivacySettingResponse(BusinessBaseResponse):
125+
data: Optional[BusinessAccountPrivacySetting] = field(default=None)
126+
127+
114128
@dataclass
115129
class BusinessVideoImpressionSource(BaseModel):
116130
impression_source: Optional[str] = field(default=None)
@@ -192,6 +206,18 @@ class BusinessPhotoPublishResponse(BusinessBaseResponse):
192206
data: Optional[BusinessPhotoPublish] = field(default=None)
193207

194208

209+
@dataclass
210+
class BusinessPublishStatus(BaseModel):
211+
status: Optional[str] = field(default=None)
212+
post_ids: Optional[List[str]] = field(default=None)
213+
reason: Optional[str] = field(default=None)
214+
215+
216+
@dataclass
217+
class BusinessPublishStatusResponse(BusinessBaseResponse):
218+
data: Optional[BusinessPublishStatus] = field(default=None)
219+
220+
195221
@dataclass
196222
class BusinessComment(BaseModel):
197223
"""

0 commit comments

Comments
 (0)