From eb7d615a25220a480b344aa23c936fd6b1d64f04 Mon Sep 17 00:00:00 2001 From: Allan Nava Date: Mon, 29 Jul 2024 22:02:12 +0200 Subject: [PATCH] added commercial api --- tiktok/commercial.go | 45 ++++++++++++++++++++++++++++++++++++ tiktok/constants.go | 2 ++ tiktok/request_commercial.go | 33 ++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 tiktok/commercial.go create mode 100644 tiktok/request_commercial.go diff --git a/tiktok/commercial.go b/tiktok/commercial.go new file mode 100644 index 0000000..9600028 --- /dev/null +++ b/tiktok/commercial.go @@ -0,0 +1,45 @@ +package tiktok + +/* +Query Ads +Use POST /v2/research/adlib/ad/query to query ads. + +HTTP URL +https://open.tiktokapis.com/v2/research/adlib/ad/query/ + +curl -L -X POST 'https://open.tiktokapis.com/v2/research/adlib/ad/query/?fields=ad.id,ad.first_shown_date,ad.last_shown_date' \ +-H 'Authorization: Bearer clt.example12345Example12345Example' \ +-H 'Content-Type: application/json' \ +--data-raw '{ + "filters":{ + "advertiser_business_ids": [3847236290405, 319282903829], + "ad_published_date_range": { + "min": "20210102", + "max": "20210109" + }, + "country_code": "FR", + "unique_users_seen_size_range": { + "min": "10K", + "max": "1M" + }, + }, + "search_term": "mobile games" +}' +*/ +func (o *tiktok) ResearchAdQuery(searchTerm string, ) { + data := map[string]string{} + data["fields"] = "ad.id,ad.first_shown_date,ad.last_shown_date" + // + request := &ResearchAdQueryRequest{ + SearchTerm: searchTerm, + } + resp, err := o.restyPostWithQueryParams(API_RESEARCH_AD_QUERY, request, data) + if err != nil { + o.debugPrint(err) + //return nil, err + } + /*if resp.IsError() { + return nil, fmt.Errorf("client access token management error %s", resp.String()) + }*/ + o.debugPrint(resp) +} \ No newline at end of file diff --git a/tiktok/constants.go b/tiktok/constants.go index d6294e9..cb3052f 100644 --- a/tiktok/constants.go +++ b/tiktok/constants.go @@ -11,6 +11,7 @@ const ( USER_INFO = "/v2/user/info/" VIDEO_LIST = "/v2/video/list/" RESEARCH_VIDEO_QUERY = "/v2/research/video/query/" + RESEARCH_AD_QUERY = "/v2/research/adlib/ad/query/" ) var ( @@ -21,4 +22,5 @@ var ( API_USER_INFO = fmt.Sprintf("%s%s", BASE_URL, USER_INFO) API_VIDEO_LIST = fmt.Sprintf("%s%s", BASE_URL, VIDEO_LIST) API_RESEARCH_VIDEO_QUERY = fmt.Sprintf("%s%s", BASE_URL, RESEARCH_VIDEO_QUERY) + API_RESEARCH_AD_QUERY = fmt.Sprintf("%s%s", BASE_URL, RESEARCH_AD_QUERY) ) \ No newline at end of file diff --git a/tiktok/request_commercial.go b/tiktok/request_commercial.go new file mode 100644 index 0000000..838556b --- /dev/null +++ b/tiktok/request_commercial.go @@ -0,0 +1,33 @@ +package tiktok + +/*{ + "filters":{ + "advertiser_business_ids": [3847236290405, 319282903829], + "ad_published_date_range": { + "min": "20210102", + "max": "20210109" + }, + "country_code": "FR", + "unique_users_seen_size_range": { + "min": "10K", + "max": "1M" + }, + }, + "search_term": "mobile games" +}*/ + +type ResearchAdQueryRequest struct { + Filters ResearchAdQueryFilter `json:"filters"` + SearchTerm string `json:"search_term"` +} + +type ResearchAdQueryFilter struct { + AdvertiserBusinessIDs []int64 `json:"advertiser_business_ids"` + AdPublishedDateRange AdPublishedDateRange `json:"ad_published_date_range"` + CountryCode string `json:"country_code"` +} + +type AdPublishedDateRange struct { + Min string `json:"min"` + Max string `json:"max"` +} \ No newline at end of file