diff --git a/tiktok/content.go b/tiktok/content.go index a017b81..564214c 100644 --- a/tiktok/content.go +++ b/tiktok/content.go @@ -1,5 +1,10 @@ package tiktok +import ( + "encoding/json" + "fmt" +) + /* Query Creator Info To initiate a direct post to a creator's account, you must first use the Query Creator Info endpoint to get the target creator's latest information. For more information about why creator information is necessary, refer to these UX guidelines. @@ -11,8 +16,19 @@ 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) { - - return nil, nil + resp, err := o.restyPost("/", nil) + if err != nil { + return nil, err + } + if resp.IsError() { + return nil, fmt.Errorf("creator info error %s", resp.String()) + } + var obj QueryCreatorInfoResponse + if err := json.Unmarshal(resp.Body(), &obj); err != nil { + return nil, err + } + o.debugPrint(obj) + return &obj, nil } /* @@ -29,21 +45,22 @@ Request: curl --location 'https://open.tiktokapis.com/v2/post/publish/video/init/' \ --header 'Authorization: Bearer act.example12345Example12345Example' \ --header 'Content-Type: application/json; charset=UTF-8' \ ---data-raw '{ - "post_info": { - "title": "this will be a funny #cat video on your @tiktok #fyp", - "privacy_level": "MUTUAL_FOLLOW_FRIENDS", - "disable_duet": false, - "disable_comment": true, - "disable_stitch": false, - "video_cover_timestamp_ms": 1000 - }, - "source_info": { - "source": "PULL_FROM_URL", - "video_url": "https://example.verified.domain.com/example_video.mp4", - } -}' + + --data-raw '{ + "post_info": { + "title": "this will be a funny #cat video on your @tiktok #fyp", + "privacy_level": "MUTUAL_FOLLOW_FRIENDS", + "disable_duet": false, + "disable_comment": true, + "disable_stitch": false, + "video_cover_timestamp_ms": 1000 + }, + "source_info": { + "source": "PULL_FROM_URL", + "video_url": "https://example.verified.domain.com/example_video.mp4", + } + }' */ func (o *tiktok) PostVideo() { - -} \ No newline at end of file + +} diff --git a/tiktok/model_content.go b/tiktok/model_content.go index 4fe8a36..ec5e955 100644 --- a/tiktok/model_content.go +++ b/tiktok/model_content.go @@ -6,7 +6,7 @@ package tiktok "creator_avatar_url": "https://lf16-tt4d.tiktokcdn.com/obj/tiktok-open-platform/8d5740ac3844be417beeacd0df75aef1", "creator_username": "tiktok", "creator_nickname": "TikTok Official", - "privacy_level_options": ["PUBLIC_TO_EVERYONE", "MUTUAL_FOLLOW_FRIENDS", "SELF_ONLY"] + "privacy_level_options": ["PUBLIC_TO_EVERYONE", "MUTUAL_FOLLOW_FRIENDS", "SELF_ONLY"] "comment_disabled": false, "duet_disabled": false, "stitch_disabled": true, @@ -21,22 +21,22 @@ package tiktok */ type QueryCreatorInfoResponse struct { - Data DataQueryCreatorInfo `json:"data"` - Error ErrorQueryCreatorInfo `json:"error"` + Data DataQueryCreatorInfo `json:"data"` + Error ErrorQueryCreatorInfo `json:"error"` } type DataQueryCreatorInfo struct { - CreatorAvatarUrl string `json:"creator_avatar_url"` - CreatorUsername string `json:"creator_username"` - CreatorNickname string `json:"creator_nickname"` - PrivacyLevelOptions []string `json:"privacy_level_options"` - CommentDisabled bool `json:"comment_disabled"` - DuetDisabled bool `json:"duet_disabled"` - StitchDisabled bool `json:"stitch_disabled"` + CreatorAvatarUrl string `json:"creator_avatar_url"` + CreatorUsername string `json:"creator_username"` + CreatorNickname string `json:"creator_nickname"` + PrivacyLevelOptions []string `json:"privacy_level_options"` + CommentDisabled bool `json:"comment_disabled"` + DuetDisabled bool `json:"duet_disabled"` + StitchDisabled bool `json:"stitch_disabled"` } type ErrorQueryCreatorInfo struct { - Code string `json:"code"` - Message string `json:"message"` - LogId string `json:"log_id"` + Code string `json:"code"` + Message string `json:"message"` + LogId string `json:"log_id"` } diff --git a/tiktok/resty.go b/tiktok/resty.go index 001ee2e..13ac8b7 100644 --- a/tiktok/resty.go +++ b/tiktok/resty.go @@ -2,6 +2,7 @@ package tiktok import ( "fmt" + "log" "github.com/go-resty/resty/v2" ) @@ -27,7 +28,7 @@ func (o *tiktok) restyPost(url string, body interface{}) (*resty.Response, error resp, err := o.restClient.R(). SetHeader("Accept", "application/json"). SetHeader("Content-Type", "application/json"). - SetHeader("Auhtorization", "Bearer "+ o.accessToken ). + SetHeader("Auhtorization", "Bearer "+o.accessToken). SetBody(body). Post(url) @@ -39,7 +40,7 @@ func (o *tiktok) restyPost(url string, body interface{}) (*resty.Response, error func (o *tiktok) restyGet(url string, queryParams map[string]string) (*resty.Response, error) { resp, err := o.restClient.R(). - SetHeader("Auhtorization", "Bearer "+ o.accessToken ). + SetHeader("Auhtorization", "Bearer "+o.accessToken). SetQueryParams(queryParams). Get(url) // @@ -48,3 +49,9 @@ func (o *tiktok) restyGet(url string, queryParams map[string]string) (*resty.Res } return resp, nil } + +func (o *tiktok) debugPrint(data ...interface{}) { + if o.debug { + log.Println(data...) + } +}