Skip to content

Commit

Permalink
added new api
Browse files Browse the repository at this point in the history
  • Loading branch information
Allan-Nava authored Jul 26, 2024
1 parent f8b0b58 commit 5f384cc
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
2 changes: 2 additions & 0 deletions tiktok/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ const (
BASE_URL = "https://open.tiktokapis.com/"
QUERY_CREATOR_INFO = "v2/post/publish/creator_info/query"
POST_PUBLISH_VIDEO_INIT = "v2/post/publish/video/init"
PUBLISH_STATUS_FETCH = "v2/post/publish/status/fetch/"
)

var (
API_QUERY_CREATOR_INFO = fmt.Sprintf("%s%s", BASE_URL, QUERY_CREATOR_INFO)
API_POST_PUBLISH_VIDEO_INIT = fmt.Sprintf("%s%s", BASE_URL, POST_PUBLISH_VIDEO_INIT)
API_PUBLISH_STATUS_FETCH = fmt.Sprintf("%s%s", BASE_URL, PUBLISH_STATUS_FETCH)
)
24 changes: 23 additions & 1 deletion tiktok/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ func (o *tiktok) PostVideoInit(title, videoUrl string, privacyLevel string) (*Pu
if !CheckPrivacyLevel(privacyLevel){
return nil, PrivacyLevelWrong
}

request := &PublishVideoRequest{
PostInfo: PostInfo{
Title: title,
PrivacyLevel: privacyLevel,
DisableDuet: false,
DisableComment: false,
DisableStitch: false,
},
SourceInfo: SourceInfo{
Source: "PULL_FROM_URL",
Expand All @@ -90,3 +92,23 @@ func (o *tiktok) PostVideoInit(title, videoUrl string, privacyLevel string) (*Pu
o.debugPrint(obj)
return &obj, nil
}


func (o *tiktok) PublishVideo(publishId string) (*PublishStatusFetchResponse, error) {
request := &PublishStatusFetchRequest{
PublishId: publishId,
}
resp, err := o.restyPost(API_PUBLISH_STATUS_FETCH, request)
if err != nil {
return nil, err
}
if resp.IsError() {
return nil, fmt.Errorf("post video init error %s", resp.String())
}
var obj PublishStatusFetchResponse
if err := json.Unmarshal(resp.Body(), &obj); err != nil {
return nil, err
}
o.debugPrint(obj)
return &obj, nil
}
12 changes: 12 additions & 0 deletions tiktok/model_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,16 @@ type PublishVideoResponse struct {

type DataPublishVideo struct {
PubblishId string `json:"publish_id"`
}

type PublishStatusFetchResponse struct {
Data DataQueryCreatorInfo `json:"data"`
Error ErrorObject `json:"error"`
}

type PublishStatusFetch struct {
Status string `json:"status"`
FailReason string `json:"fail_reason"`
UploadedBytes int64 `json:"uploaded_bytes"`
PublicalyAvailablePostId []int64 `json:"publicaly_available_post_id"`
}
6 changes: 5 additions & 1 deletion tiktok/request_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ type PostInfo struct {
DisableDuet bool `json:"disable_duet"`
DisableComment bool `json:"disable_comment"`
DisableStitch bool `json:"disable_stitch"`
VideoCoverTimestampMS int `json:"video_cover_timestamp_ms"`
VideoCoverTimestampMS int64 `json:"video_cover_timestamp_ms"`
}

type SourceInfo struct {
Source string `json:"source"`
VideoUrl string `json:"video_url"`
}

type PublishStatusFetchRequest struct {
PublishId string `json:"publish_id"`
}
1 change: 1 addition & 0 deletions tiktok/tiktok.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type ITiktok interface {
IsDebug() bool
CreatorInfo() (*QueryCreatorInfoResponse, error)
PostVideoInit(title, videoUrl string, privacyLevel string) (*PublishVideoResponse, error)
PublishVideo(publishId string) (*PublishStatusFetchResponse, error)
//
}

Expand Down

0 comments on commit 5f384cc

Please sign in to comment.