Skip to content

Commit

Permalink
added PostPhotoInit
Browse files Browse the repository at this point in the history
  • Loading branch information
Allan-Nava authored Jul 28, 2024
1 parent dfd4bdd commit 6a62e97
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
39 changes: 38 additions & 1 deletion tiktok/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,41 @@ curl --location 'https://open.tiktokapis.com/v2/post/publish/content/init/' \
"post_mode": "MEDIA_UPLOAD",
"media_type": "PHOTO"
}'
*/
*/

func (o *tiktok) PostPhotoInit(title, description, privacyLevel string, photoUrls []string, photoMode string) (*PublishStatusFetchResponse, error) {
if !CheckPrivacyLevel(privacyLevel){
return nil, PrivacyLevelWrong
}
if !CheckPostMode(photoMode){
return nil, PhotoModeWrong
}
request := &PublishPhotoRequest{
PostInfo: PostPhotoInfo{
Title: title,
PrivacyLevel: privacyLevel,
DisableComment: false,
AutoAddMusic: true,
},
SourceInfo: PhotoSourceInfo{
Source: "PULL_FROM_URL",
PhotoCoverIndex: 1,
PhotoImages: photoUrls,
},
PostMode: photoMode,
MediaType: "PHOTO",
}
resp, err := o.restyPost(POST_PUBLISH_CONTENT_INIT, 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
}
1 change: 1 addition & 0 deletions tiktok/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import "errors"

var (
PrivacyLevelWrong = errors.New("Privacy Level is not correct!")
PhotoModeWrong = errors.New("Photo mode is not correct!")
)
18 changes: 18 additions & 0 deletions tiktok/post_mode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package tiktok

type PostModeOptions string

const (
DIRECT_POST PostModeOptions = "DIRECT_POST"
MEDIA_UPLOAD PostModeOptions = "MEDIA_UPLOAD"
)

// CheckPostMode checks if the given string matches any PostModeOptions
func CheckPostMode(mode string) bool {
switch PostModeOptions(mode) {
case DIRECT_POST, MEDIA_UPLOAD:
return true
default:
return false
}
}
28 changes: 27 additions & 1 deletion tiktok/request_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ package tiktok
}
}
*/
/*type BasePostInfo struct {
}*/

type PublishVideoRequest struct {
PostInfo PostInfo `json:"post_info"`
SourceInfo SourceInfo `json:"source_info"`
Expand All @@ -37,4 +40,27 @@ type SourceInfo struct {

type PublishStatusFetchRequest struct {
PublishId string `json:"publish_id"`
}
}


type PublishPhotoRequest struct {
PostInfo PostPhotoInfo `json:"post_info"`
SourceInfo PhotoSourceInfo `json:"source_info"`
PostMode string `json:"post_mode"` // DIRECT_POST | MEDIA_UPLAOD
MediaType string `json:"media_type"` // PHOTO
}

type PostPhotoInfo struct {
Title string `json:"title"`
Description string `json:"description"`
PrivacyLevel string `json:"privacy_level"`
DisableComment bool `json:"disable_comment"`
AutoAddMusic bool `json:"auto_add_music"`
}

type PhotoSourceInfo struct {
Source string `json:"source"`
PhotoCoverIndex int `json:"photo_cover_index"`
PhotoImages []string `json:"photo_images"`
}

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)
PostPhotoInit(title, description, privacyLevel string, photoUrls []string, photoMode string) (*PublishStatusFetchResponse, error)
UserInfo() (*UserInfoResponse, error)
//
}
Expand Down

0 comments on commit 6a62e97

Please sign in to comment.