Skip to content

Commit

Permalink
Merge pull request #18 from MerleLiuKun/feat-publish-photo
Browse files Browse the repository at this point in the history
Feat publish photo
  • Loading branch information
MerleLiuKun authored Aug 7, 2024
2 parents 3ec3342 + 2e1adc4 commit a8bf864
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', "3.11", "3.12"]
include:
- python-version: '3.10'
update-coverage: true
Expand All @@ -35,7 +35,7 @@ jobs:
run: poetry run pytest
- name: Upload coverage to Codecov
if: ${{ matrix.update-coverage }}
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
Expand Down
35 changes: 35 additions & 0 deletions pytiktok/business_account_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,41 @@ def create_video(
else mds.BusinessVideoPublishResponse.new_from_json_dict(data)
)

def create_photo(
self,
business_id: str,
photo_images: List[str],
post_info: dict,
photo_cover_index: int = 0,
return_json: bool = False,
) -> Union[mds.BusinessPhotoPublishResponse, dict]:
"""
Publish a photo post to an owned TikTok Account.
:param business_id: Application specific unique identifier for the TikTok account.
:param photo_images: A list of up to 35 publicly accessible HTTP(s) URLs for the photo content to be published.
:param post_info: Information about the photo post.
- privacy_level is Required field.
- Other fields are optional
:param photo_cover_index: The index of the photo to be used as the cover for the post.
O is the first photo.
:param return_json: Type for returned data. If you set True JSON data will be returned.
:return: Photo publish response.
"""

data = {
"business_id": business_id,
"photo_images": photo_images,
"photo_cover_index": photo_cover_index,
"post_info": post_info,
}
resp = self._request(verb="POST", path="business/photo/publish/", json=data)
data = self.parse_response(resp)
return (
data
if return_json
else mds.BusinessPhotoPublishResponse.new_from_json_dict(data)
)

def get_video_comments(
self,
business_id: str,
Expand Down
19 changes: 18 additions & 1 deletion pytiktok/models/business_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class BusinessVideosResponse(BusinessBaseResponse):


@dataclass
class BusinessVideoPublish(BusinessBaseResponse):
class BusinessVideoPublish(BaseModel):
"""
Refer: https://ads.tiktok.com/marketing_api/docs?id=1733584024973313
"""
Expand All @@ -178,14 +178,31 @@ class BusinessVideoPublishResponse(BusinessBaseResponse):
data: Optional[BusinessVideoPublish] = field(default=None)


@dataclass
class BusinessPhotoPublish(BusinessVideoPublish):
"""
https://business-api.tiktok.com/portal/docs?id=1803630424390658
"""

...


@dataclass
class BusinessPhotoPublishResponse(BusinessBaseResponse):
data: Optional[BusinessPhotoPublish] = field(default=None)


@dataclass
class BusinessComment(BaseModel):
"""
Refer: https://ads.tiktok.com/marketing_api/docs?id=1733329505077250
"""

comment_id: Optional[str] = field(default=None)
unique_identifier: Optional[str] = field(default=None, repr=True)
video_id: Optional[str] = field(default=None, repr=False)
# Note: user_id now is To-be-deprecated, will be deprecated in the next API version.
# Please use unique_identifier instead.
user_id: Optional[str] = field(default=None, repr=False)
create_time: Optional[int] = field(default=None)
text: Optional[str] = field(default=None)
Expand Down

0 comments on commit a8bf864

Please sign in to comment.