Skip to content

Commit

Permalink
added creatorinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
allan committed Jul 25, 2024
1 parent d49514a commit f6c70fb
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 33 deletions.
53 changes: 35 additions & 18 deletions tiktok/content.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
}

/*
Expand All @@ -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() {
}

}
26 changes: 13 additions & 13 deletions tiktok/model_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"`
}
11 changes: 9 additions & 2 deletions tiktok/resty.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tiktok

import (
"fmt"
"log"

"github.com/go-resty/resty/v2"
)
Expand All @@ -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)

Expand All @@ -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)
//
Expand All @@ -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...)
}
}

0 comments on commit f6c70fb

Please sign in to comment.