From 074e5c65b849011697323969cd07be843314cd0e Mon Sep 17 00:00:00 2001 From: Allan Nava Date: Thu, 25 Jul 2024 22:39:14 +0200 Subject: [PATCH] added new methods --- tiktok/constants.go | 3 ++- tiktok/content.go | 3 ++- tiktok/request_content.go | 36 ++++++++++++++++++++++++++++++++++++ tiktok/resty.go | 2 ++ tiktok/tiktok.go | 11 +++++++++++ 5 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 tiktok/request_content.go diff --git a/tiktok/constants.go b/tiktok/constants.go index bdc95e8..9cd9e97 100644 --- a/tiktok/constants.go +++ b/tiktok/constants.go @@ -2,4 +2,5 @@ package tiktok const ( BASE_URL = "https://open.tiktokapis.com" -) \ No newline at end of file + QUERY_CREATOR_INFO = "v2/post/publish/creator_info/query" +) diff --git a/tiktok/content.go b/tiktok/content.go index 62e2ac1..a017b81 100644 --- a/tiktok/content.go +++ b/tiktok/content.go @@ -10,8 +10,9 @@ curl --location --request POST 'https://open.tiktokapis.com/v2/post/publish/crea --header 'Authorization: Bearer act.example12345Example12345Example' \ --header 'Content-Type: application/json; charset=UTF-8' */ -func (o *tiktok) CreatorInfo() { +func (o *tiktok) CreatorInfo() (*QueryCreatorInfoResponse, error) { + return nil, nil } /* diff --git a/tiktok/request_content.go b/tiktok/request_content.go new file mode 100644 index 0000000..5175d1f --- /dev/null +++ b/tiktok/request_content.go @@ -0,0 +1,36 @@ +package tiktok + +/* +{ + "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", + } +} +*/ +type PublishVideoRequest struct { + PostInfo PostInfo `json:"post_info"` + SourceInfo SourceInfo `json:"source_info"` +} + +type PostInfo struct { + Title string `json:"title"` + PrivacyLevel string `json:"privacy_level"` + DisableDuet bool `json:"disable_duet"` + DisableComment bool `json:"disable_comment"` + DisableStitch bool `json:"disable_stitch"` + VideoCoverTimestampMS int `json:"video_cover_timestamp_ms"` +} + +type SourceInfo struct { + Source string `json:"source"` + VideoUrl string `json:"video_url"` +} \ No newline at end of file diff --git a/tiktok/resty.go b/tiktok/resty.go index f9aee80..9425ede 100644 --- a/tiktok/resty.go +++ b/tiktok/resty.go @@ -27,6 +27,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 ). SetBody(body). Post(url) @@ -38,6 +39,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 ). SetQueryParams(queryParams). Get(url) // diff --git a/tiktok/tiktok.go b/tiktok/tiktok.go index 675fe2f..e77bbac 100644 --- a/tiktok/tiktok.go +++ b/tiktok/tiktok.go @@ -6,6 +6,7 @@ type ITiktok interface { // HealthCheck() error IsDebug() bool + CreatorInfo() (*QueryCreatorInfoResponse, error) // } @@ -14,6 +15,7 @@ type tiktok struct { debug bool clientKey string clientSecret string + accessToken string } func NewTikTok(clientKey, clientSecret string, isDebug bool) (ITiktok, error) { @@ -27,3 +29,12 @@ func NewTikTok(clientKey, clientSecret string, isDebug bool) (ITiktok, error) { o.restClient.SetBaseURL(BASE_URL) return o, nil } + + +func (o *tiktok) SetAccessToken(token string){ + o.accessToken = token +} + +func (o *tiktok) GetAccessToken() string { + return o.accessToken +} \ No newline at end of file