Skip to content

Commit

Permalink
added postvideo init
Browse files Browse the repository at this point in the history
  • Loading branch information
Allan-Nava authored Jul 26, 2024
1 parent 3cc05f7 commit 41bb2af
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
11 changes: 9 additions & 2 deletions tiktok/constants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package tiktok

const (
BASE_URL = "https://open.tiktokapis.com"
QUERY_CREATOR_INFO = "v2/post/publish/creator_info/query"
BASE_URL = "https://open.tiktokapis.com/"
QUERY_CREATOR_INFO = "v2/post/publish/creator_info/query"
POST_PUBLISH_VIDEO_INIT = "v2/post/publish/video/init"
)


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)
)
27 changes: 24 additions & 3 deletions tiktok/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ curl --location --request POST 'https://open.tiktokapis.com/v2/post/publish/crea
--header 'Content-Type: application/json; charset=UTF-8'
*/
func (o *tiktok) CreatorInfo() (*QueryCreatorInfoResponse, error) {
resp, err := o.restyPost("/", nil)
resp, err := o.restyPost(API_QUERY_CREATOR_INFO, nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -61,6 +61,27 @@ curl --location 'https://open.tiktokapis.com/v2/post/publish/video/init/' \
}
}'
*/
func (o *tiktok) PostVideo() {

func (o *tiktok) PostVideoInit(title, videoUrl string, privacyLevel string) (*PublishVideoResponse, error) {
request := &PublishVideoRequest{
PostInfo: PostInfo{
Title: title,
},
SourceInfo: SourceInfo{
Source: "PULL_FROM_URL",
VideoUrl: videoUrl

Check failure on line 71 in tiktok/content.go

View workflow job for this annotation

GitHub Actions / build (1.19.x)

syntax error: unexpected newline in composite literal; possibly missing comma or }

Check failure on line 71 in tiktok/content.go

View workflow job for this annotation

GitHub Actions / build (1.20.x)

syntax error: unexpected newline in composite literal; possibly missing comma or }

Check failure on line 71 in tiktok/content.go

View workflow job for this annotation

GitHub Actions / build (1.21.x)

syntax error: unexpected newline in composite literal; possibly missing comma or }

Check failure on line 71 in tiktok/content.go

View workflow job for this annotation

GitHub Actions / build (1.21.x)

syntax error: unexpected newline in composite literal; possibly missing comma or }

Check failure on line 71 in tiktok/content.go

View workflow job for this annotation

GitHub Actions / build (1.22.x)

syntax error: unexpected newline in composite literal; possibly missing comma or }
}

Check failure on line 72 in tiktok/content.go

View workflow job for this annotation

GitHub Actions / build (1.19.x)

syntax error: unexpected newline in composite literal; possibly missing comma or }

Check failure on line 72 in tiktok/content.go

View workflow job for this annotation

GitHub Actions / build (1.20.x)

syntax error: unexpected newline in composite literal; possibly missing comma or }

Check failure on line 72 in tiktok/content.go

View workflow job for this annotation

GitHub Actions / build (1.21.x)

syntax error: unexpected newline in composite literal; possibly missing comma or }

Check failure on line 72 in tiktok/content.go

View workflow job for this annotation

GitHub Actions / build (1.21.x)

syntax error: unexpected newline in composite literal; possibly missing comma or }

Check failure on line 72 in tiktok/content.go

View workflow job for this annotation

GitHub Actions / build (1.22.x)

syntax error: unexpected newline in composite literal; possibly missing comma or }
}
resp, err := o.restyPost(API_POST_PUBLISH_VIDEO_INIT, request)
if err != nil {
return nil, err
}
if resp.IsError() {
return nil, fmt.Errorf("post video init error %s", resp.String())
}
var obj PublishVideoResponse
if err := json.Unmarshal(resp.Body(), &obj); err != nil {
return nil, err
}
o.debugPrint(obj)
return &obj, nil
}
13 changes: 11 additions & 2 deletions tiktok/model_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package tiktok

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

type DataQueryCreatorInfo struct {
Expand All @@ -35,8 +35,17 @@ type DataQueryCreatorInfo struct {
StitchDisabled bool `json:"stitch_disabled"`
}

type ErrorQueryCreatorInfo struct {
type ErrorObject struct {
Code string `json:"code"`
Message string `json:"message"`
LogId string `json:"log_id"`
}

type PublishVideoResponse struct {
Data DataPublishVideo `json:"data"`
Error ErrorObject `json:"error"`
}

type DataPublishVideo struct {
PubblishId 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 @@ -7,6 +7,7 @@ type ITiktok interface {
HealthCheck() error
IsDebug() bool
CreatorInfo() (*QueryCreatorInfoResponse, error)
PostVideoInit(title, videoUrl string, privacyLevel string) (*PublishVideoResponse, error)
//
}

Expand Down

0 comments on commit 41bb2af

Please sign in to comment.