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