11"""
22Core API impl.
33"""
4-
4+ import io
55import json
66from typing import Optional , List , Union
77
@@ -169,6 +169,7 @@ def _request(
169169 params : Optional [dict ] = None ,
170170 data : Optional [dict ] = None ,
171171 json : Optional [dict ] = None ,
172+ files : Optional [dict ] = None ,
172173 enforce_auth : bool = True ,
173174 ) -> Response :
174175 """
@@ -178,6 +179,7 @@ def _request(
178179 :param params: The url params to send in the body of the request.
179180 :param data: The form data to send in the body of the request.
180181 :param json: The json data to send in the body of the request.
182+ :param files: Files to send in the body of the request.
181183 :param enforce_auth: Does the request require authentication.
182184 :return: A json object
183185 """
@@ -197,6 +199,7 @@ def _request(
197199 params = params ,
198200 data = data ,
199201 json = json ,
202+ files = files ,
200203 timeout = self .timeout ,
201204 proxies = self .proxies ,
202205 )
@@ -316,6 +319,7 @@ def create_video(
316319 business_id : str ,
317320 video_url : str ,
318321 post_info : dict ,
322+ custom_thumbnail_url : Optional [str ] = None ,
319323 return_json : bool = False ,
320324 ) -> Union [mds .BusinessVideoPublishResponse , dict ]:
321325 """
@@ -324,6 +328,8 @@ def create_video(
324328 :param business_id: Application specific unique identifier for the TikTok account.
325329 :param video_url: A publicly accessible HTTP(s) URL for the video content to be published -
326330 with a minimum recommended TTL of 30 minutes.
331+ :param custom_thumbnail_url: A publicly accessible HTTP(s) URL for a custom image to be used as the video’s cover photo.
332+ When custom_thumbnail_url is specified, thumbnail_offset will be ignored.
327333 :param post_info: Required field.
328334 Pass empty object if not using caption, disable_comment, disable_duet or disable_stitch.
329335 :param return_json: Type for returned data. If you set True JSON data will be returned.
@@ -334,6 +340,8 @@ def create_video(
334340 "video_url" : video_url ,
335341 "post_info" : post_info ,
336342 }
343+ if custom_thumbnail_url is not None :
344+ data ["custom_thumbnail_url" ] = custom_thumbnail_url
337345
338346 resp = self ._request (verb = "POST" , path = "business/video/publish/" , json = data )
339347 data = self .parse_response (resp )
@@ -507,17 +515,56 @@ def get_comment_replies(
507515 else mds .BusinessCommentsResponse .new_from_json_dict (data )
508516 )
509517
518+ def upload_comment_image (self , business_id : str , image_data : bytes , return_json : bool = False ) -> Union [
519+ mds .BusinessCommentImageResponse , dict ]:
520+ """
521+ upload an image for a new comment or for a reply to an existing comment.
522+ :param business_id: Application specific unique identifier for the TikTok account.
523+ :param image_data: Image file bytes data.
524+ :param return_json: Type for returned data. If you set True JSON data will be returned.
525+ :return: Comment Image's data.
526+ """
527+ files = {"image_file" : io .BytesIO (image_data )}
528+ resp = self ._request (
529+ verb = "POST" ,
530+ path = "business/comment/image/upload/" ,
531+ data = {"business_id" : business_id },
532+ files = files ,
533+ )
534+ data = self .parse_response (resp )
535+ return (
536+ data
537+ if return_json
538+ else mds .BusinessCommentImageResponse .new_from_json_dict (data )
539+ )
540+
510541 def create_comment (
511- self , business_id : str , video_id : str , text : str , return_json : bool = False
542+ self ,
543+ business_id : str ,
544+ video_id : str ,
545+ text : Optional [str ] = None ,
546+ image_uri : Optional [str ] = None ,
547+ image_width : Optional [int ] = None ,
548+ image_height : Optional [int ] = None ,
549+ return_json : bool = False
512550 ) -> Union [mds .BusinessCommentResponse , dict ]:
513551 """
514552 :param business_id: Application specific unique identifier for the TikTok account.
515553 :param video_id: Unique identifier for owned TikTok video to create comments on.
516554 :param text: Text content of the comment to create. Max length of 150 characters.
555+ :param image_uri: URI for the reply image. Returned by upload endpoint.
556+ :param image_width: Required when image_uri is specified. Returned by upload endpoint.
557+ :param image_height: Required when image_uri is specified. Returned by upload endpoint.
517558 :param return_json: Type for returned data. If you set True JSON data will be returned.
518559 :return: Comment's data.
519560 """
520- data = {"business_id" : business_id , "video_id" : video_id , "text" : text }
561+ data = {"business_id" : business_id , "video_id" : video_id }
562+ if text is not None :
563+ data ["text" ] = text
564+ if image_uri is not None :
565+ data ["image_uri" ] = image_uri
566+ data ["image_width" ] = image_width
567+ data ["image_height" ] = image_height
521568
522569 resp = self ._request (verb = "POST" , path = "business/comment/create/" , json = data )
523570 data = self .parse_response (resp )
@@ -532,23 +579,34 @@ def create_reply(
532579 business_id : str ,
533580 video_id : str ,
534581 comment_id : str ,
535- text : str ,
582+ text : Optional [str ] = None ,
583+ image_uri : Optional [str ] = None ,
584+ image_width : Optional [int ] = None ,
585+ image_height : Optional [int ] = None ,
536586 return_json : bool = False ,
537587 ) -> Union [mds .BusinessCommentResponse , dict ]:
538588 """
539589 :param business_id: Application specific unique identifier for the TikTok account.
540590 :param video_id: Unique identifier for owned TikTok video to create comments on.
541591 :param comment_id: Unique identifier for comment on an owned TikTok video to create reply on.
542592 :param text: Text content of the comment to create. Max length of 150 characters.
593+ :param image_uri: URI for the reply image. Returned by upload endpoint.
594+ :param image_width: Required when image_uri is specified. Returned by upload endpoint.
595+ :param image_height: Required when image_uri is specified. Returned by upload endpoint.
543596 :param return_json: Type for returned data. If you set True JSON data will be returned.
544597 :return: Comment's data.
545598 """
546599 data = {
547600 "business_id" : business_id ,
548601 "video_id" : video_id ,
549602 "comment_id" : comment_id ,
550- "text" : text ,
551603 }
604+ if text is not None :
605+ data ["text" ] = text
606+ if image_uri is not None :
607+ data ["image_uri" ] = image_uri
608+ data ["image_width" ] = image_width
609+ data ["image_height" ] = image_height
552610
553611 resp = self ._request (
554612 verb = "POST" , path = "business/comment/reply/create/" , json = data
@@ -813,3 +871,22 @@ def get_url_property_list(
813871 if return_json
814872 else mds .BusinessUrlPropertyInfoListResponse .new_from_json_dict (data )
815873 )
874+
875+ def get_business_category_benchmarks (
876+ self , business_id : str , business_category : str , return_json : bool = False
877+ ) -> Union [mds .BusinessCategoryBenchmarksResponse , dict ]:
878+ """
879+ To retrieve the benchmarks specific to a business category.
880+ :param business_id: Application specific unique identifier for the TikTok account.
881+ :param business_category: Business category. For enum values, see List of values for [business_category](https://business-api.tiktok.com/gateway/docs/index?identify_key=c0138ffadd90a955c1f0670a56fe348d1d40680b3c89461e09f78ed26785164b&language=ENGLISH&doc_id=1822388944791617#item-link-List%20of%20values%20for%20business_category).
882+ :param return_json: Type for returned data. If you set True JSON data will be returned.
883+ :return: Benchmark response.
884+ """
885+ params = {"business_id" : business_id , "business_category" : business_category }
886+ resp = self ._request (verb = "GET" , path = "business/benchmark/" , params = params )
887+ data = self .parse_response (resp )
888+ return (
889+ data
890+ if return_json
891+ else mds .BusinessCategoryBenchmarksResponse .new_from_json_dict (data )
892+ )
0 commit comments