1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Promopult\TikTokMarketingApi\Service; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @psalm-suppress UnusedClass |
9
|
|
|
*/ |
10
|
|
|
final class Campaign extends \Promopult\TikTokMarketingApi\AbstractService |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Getting Campaigns |
14
|
|
|
* |
15
|
|
|
* @param int $advertiserId Advertiser ID |
16
|
|
|
* @param ?array $fields Return field, optional values "campaign_id", "campaign_name", "advertiser_id", |
17
|
|
|
* "budget", "budget_mode", "status", "opt_status", "objective", "objective_type", |
18
|
|
|
* "create_time", "modify_time", "is_new_structure", "split_test_variable". |
19
|
|
|
* When not specified, all fields are returned by default. |
20
|
|
|
* @param ?array $filtering Filters on the data. This parameter is an array of filter objects. |
21
|
|
|
* @param ?int $page Current page number. Default value: 1,value range: ≥ 1 |
22
|
|
|
* @param ?int $pageSize Page size,Default value: 10,Range of values: 1-1000 |
23
|
|
|
* |
24
|
|
|
* @return array |
25
|
|
|
* |
26
|
|
|
* @throws \Throwable |
27
|
|
|
* |
28
|
|
|
* @see https://ads.tiktok.com/marketing_api/docs?id=100528 |
29
|
|
|
*/ |
30
|
|
|
public function get( |
31
|
|
|
int $advertiserId, |
32
|
|
|
?array $fields = null, |
33
|
|
|
?array $filtering = null, |
34
|
|
|
?int $page = null, |
35
|
|
|
?int $pageSize = null |
36
|
|
|
): array { |
37
|
|
|
return $this->requestApi( |
38
|
|
|
'GET', |
39
|
|
|
'/open_api/v1.3/campaign/get/', |
40
|
|
|
[ |
41
|
|
|
'advertiser_id' => $advertiserId, |
42
|
|
|
'fields' => $fields, |
43
|
|
|
'filtering' => $filtering, |
44
|
|
|
'page' => $page, |
45
|
|
|
'page_size' => $pageSize |
46
|
|
|
] |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Creating a Campaign |
52
|
|
|
* |
53
|
|
|
* @param int $advertiserId Advertiser ID |
54
|
|
|
* @param string $campaignName Campaign name. It can contain up to 512 characters. Emoji is not supported. |
55
|
|
|
* @param string $objectiveType Advertising objective. |
56
|
|
|
* @param string $budgetMode Budget type. |
57
|
|
|
* @param ?float $budget Campaign budget, required when is 'BUDGET_MODE_DAY' or 'BUDGET_MODE_TOTAL'. |
58
|
|
|
* @param ?string $splitTestVariable Split Test variables. Values: TARGETING, BIDDING_OPTIMIZATION, CREATIVE. |
59
|
|
|
* |
60
|
|
|
* @return array |
61
|
|
|
* |
62
|
|
|
* @throws \Throwable |
63
|
|
|
* |
64
|
|
|
* @see https://ads.tiktok.com/marketing_api/docs?id=100528 |
65
|
|
|
*/ |
66
|
|
|
public function create( |
67
|
|
|
int $advertiserId, |
68
|
|
|
string $campaignName, |
69
|
|
|
string $objectiveType, |
70
|
|
|
string $budgetMode, |
71
|
|
|
?float $budget = null, |
72
|
|
|
?string $splitTestVariable = null |
73
|
|
|
): array { |
74
|
|
|
return $this->requestApi( |
75
|
|
|
'POST', |
76
|
|
|
'/open_api/v1.3/campaign/create/', |
77
|
|
|
[ |
78
|
|
|
'advertiser_id' => $advertiserId, |
79
|
|
|
'budget' => $budget, |
80
|
|
|
'budget_mode' => $budgetMode, |
81
|
|
|
'campaign_name' => $campaignName, |
82
|
|
|
'objective_type' => $objectiveType, |
83
|
|
|
'split_test_variable' => $splitTestVariable |
84
|
|
|
] |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Creating a Campaign |
90
|
|
|
* |
91
|
|
|
* @param int $advertiserId Advertiser ID |
92
|
|
|
* @param string $campaignName Campaign name. It can contain up to 512 characters. Emoji is not supported. |
93
|
|
|
* @param string $objectiveType Advertising objective. |
94
|
|
|
* @param string $budgetMode Budget type. |
95
|
|
|
* @param ?float $budget Campaign budget, required when is 'BUDGET_MODE_DAY' or 'BUDGET_MODE_TOTAL'. |
96
|
|
|
* note: |
97
|
|
|
* 1. Unlimited budget can be changed to limited |
98
|
|
|
* 2. Daily budget and total budget cannot be switched with each other. |
99
|
|
|
* |
100
|
|
|
* @return array |
101
|
|
|
* |
102
|
|
|
* @throws \Throwable |
103
|
|
|
* |
104
|
|
|
* @see https://ads.tiktok.com/marketing_api/docs?id=100528 |
105
|
|
|
*/ |
106
|
|
|
public function update( |
107
|
|
|
int $advertiserId, |
108
|
|
|
string $campaignName, |
109
|
|
|
string $objectiveType, |
110
|
|
|
string $budgetMode, |
111
|
|
|
?float $budget = null |
112
|
|
|
): array { |
113
|
|
|
return $this->requestApi( |
114
|
|
|
'POST', |
115
|
|
|
'/open_api/v1.3/campaign/update/', |
116
|
|
|
[ |
117
|
|
|
'advertiser_id' => $advertiserId, |
118
|
|
|
'budget' => $budget, |
119
|
|
|
'budget_mode' => $budgetMode, |
120
|
|
|
'campaign_name' => $campaignName, |
121
|
|
|
'objective_type' => $objectiveType |
122
|
|
|
] |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Modifying the Status of a Campaign |
128
|
|
|
* |
129
|
|
|
* @param int $advertiserId Advertiser ID |
130
|
|
|
* @param array $campaignIds A list of campaign IDs, with an allowed quantity range from 1-100 |
131
|
|
|
* @param string $optStatus The operation being made , optional values include: DELETE,DISABLE,ENABLE |
132
|
|
|
* Note: The status of deleted ads cannot be modified. |
133
|
|
|
* @return array |
134
|
|
|
* @throws \Throwable |
135
|
|
|
*/ |
136
|
|
|
public function updateStatus( |
137
|
|
|
int $advertiserId, |
138
|
|
|
array $campaignIds, |
139
|
|
|
string $optStatus |
140
|
|
|
): array { |
141
|
|
|
return $this->requestApi( |
142
|
|
|
'POST', |
143
|
|
|
'/open_api/v1.3/campaign/update/status/', |
144
|
|
|
[ |
145
|
|
|
'advertiser_id' => $advertiserId, |
146
|
|
|
'campaign_ids' => $campaignIds, |
147
|
|
|
'opt_status' => $optStatus |
148
|
|
|
] |
149
|
|
|
); |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|