Skip to content

Commit

Permalink
added commercial api
Browse files Browse the repository at this point in the history
  • Loading branch information
Allan-Nava authored Jul 29, 2024
1 parent b517af2 commit eb7d615
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tiktok/commercial.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 2 additions & 0 deletions tiktok/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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)
)
33 changes: 33 additions & 0 deletions tiktok/request_commercial.go
Original file line number Diff line number Diff line change
@@ -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"`
}

0 comments on commit eb7d615

Please sign in to comment.