Skip to content

Commit

Permalink
added videos list
Browse files Browse the repository at this point in the history
  • Loading branch information
Allan-Nava authored Jul 28, 2024
1 parent e33be5c commit fdafe4c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tiktok/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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)
)
30 changes: 30 additions & 0 deletions tiktok/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
15 changes: 15 additions & 0 deletions tiktok/model_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
3 changes: 3 additions & 0 deletions tiktok/request_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ type PhotoSourceInfo struct {
PhotoImages []string `json:"photo_images"`
}

type VideoListRequest struct {
MaxCount int64 `json:"max_count"`
}
1 change: 1 addition & 0 deletions tiktok/tiktok.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
//
Expand Down

0 comments on commit fdafe4c

Please sign in to comment.