From fdafe4cdc9b0d984066582f505908e4efa6300c7 Mon Sep 17 00:00:00 2001 From: Allan Nava Date: Sun, 28 Jul 2024 14:02:24 +0200 Subject: [PATCH] added videos list --- tiktok/constants.go | 2 ++ tiktok/content.go | 30 ++++++++++++++++++++++++++++++ tiktok/model_content.go | 15 +++++++++++++++ tiktok/request_content.go | 3 +++ tiktok/tiktok.go | 1 + 5 files changed, 51 insertions(+) diff --git a/tiktok/constants.go b/tiktok/constants.go index 40fab0f..d02d1ff 100644 --- a/tiktok/constants.go +++ b/tiktok/constants.go @@ -9,6 +9,7 @@ const ( PUBLISH_STATUS_FETCH = "v2/post/publish/status/fetch/" POST_PUBLISH_CONTENT_INIT = "/v2/post/publish/content/init/" USER_INFO = "/v2/user/info/" + VIDEO_LIST = "/v2/video/list/" ) var ( @@ -17,4 +18,5 @@ var ( API_PUBLISH_STATUS_FETCH = fmt.Sprintf("%s%s", BASE_URL, PUBLISH_STATUS_FETCH) API_POST_PUBLISH_CONTENT_INIT = fmt.Sprintf("%s%s", BASE_URL, POST_PUBLISH_CONTENT_INIT) API_USER_INFO = fmt.Sprintf("%s%s", BASE_URL, USER_INFO) + API_VIDEO_LIST = fmt.Sprintf("%s%s", BASE_URL, VIDEO_LIST) ) diff --git a/tiktok/content.go b/tiktok/content.go index 14594d5..eed6363 100644 --- a/tiktok/content.go +++ b/tiktok/content.go @@ -188,4 +188,34 @@ func (o *tiktok) PostPhotoInit(title, description, privacyLevel string, photoUrl } o.debugPrint(obj) return &obj, nil +} + + +/* List Videos +The /v2/video/list/ endpoint can return a paginated list for the given user's public TikTok video posts, sorted by create_time in descending order. + +curl -L -X POST 'https://open.tiktokapis.com/v2/video/list/?fields=cover_image_url,id,title' \ +-H 'Authorization: Bearer act.example12345Example12345Example' \ +-H 'Content-Type: application/json' \ +--data-raw '{ + "max_count": 20 +}' +*/ +func (o *tiktok) GetVideoList(count int64) (*VideoListResponse, error) { + request := &VideoListRequest{ + MaxCount: count, + } + resp, err := o.restyPost(API_VIDEO_LIST, request) + if err != nil { + return nil, err + } + if resp.IsError() { + return nil, fmt.Errorf("post video init error %s", resp.String()) + } + var obj VideoListResponse + if err := json.Unmarshal(resp.Body(), &obj); err != nil { + return nil, err + } + o.debugPrint(obj) + return &obj, nil } \ No newline at end of file diff --git a/tiktok/model_content.go b/tiktok/model_content.go index eb0b334..09f8cb5 100644 --- a/tiktok/model_content.go +++ b/tiktok/model_content.go @@ -54,4 +54,19 @@ type PublishStatusFetch struct { FailReason string `json:"fail_reason"` UploadedBytes int64 `json:"uploaded_bytes"` PublicalyAvailablePostId []int64 `json:"publicaly_available_post_id"` +} + +type VideoListResponse struct { + Data DataVideoList `json:"data"` + Error ErrorObject `json:"error"` +} + +type DataVideoList struct { + Videos []Video `json:"videos"` +} + +type Video struct { + ID string `json:"id"` + Title string `json:"title"` + CoverImageUrl string `json:"cover_image_url"` } \ No newline at end of file diff --git a/tiktok/request_content.go b/tiktok/request_content.go index ce2a769..8b59ae3 100644 --- a/tiktok/request_content.go +++ b/tiktok/request_content.go @@ -64,3 +64,6 @@ type PhotoSourceInfo struct { PhotoImages []string `json:"photo_images"` } +type VideoListRequest struct { + MaxCount int64 `json:"max_count"` +} \ No newline at end of file diff --git a/tiktok/tiktok.go b/tiktok/tiktok.go index 9a8d9fb..367cf59 100644 --- a/tiktok/tiktok.go +++ b/tiktok/tiktok.go @@ -13,6 +13,7 @@ type ITiktok interface { CreatorInfo() (*QueryCreatorInfoResponse, error) PostVideoInit(title, videoUrl string, privacyLevel string) (*PublishVideoResponse, error) PublishVideo(publishId string) (*PublishStatusFetchResponse, error) + GetVideoList(count int64) (*VideoListResponse, error) PostPhotoInit(title, description, privacyLevel string, photoUrls []string, photoMode string) (*PublishStatusFetchResponse, error) UserInfo() (*UserInfoResponse, error) //