22 Core API impl.
33"""
44
5+ import json
56from typing import Optional , List , Union
67
78import 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 ,
0 commit comments