Google Adwords API PHP Client Add Keywords to Ad Group in Bulk
-
15-04-2021 - |
문제
To add an array of $keywords
to my ad group I am currently using the following code:
$adGroupCriterionService = $adwordsUser->GetService('AdGroupCriterionService', 'v201109');
$operations = array();
foreach ($keywords AS $keyword) {
$keywordobj = new Keyword();
$keywordobj->text = $keyword;
$keywordobj->matchType = 'BROAD';
$keywordAdGroupCriterion = new BiddableAdGroupCriterion();
$keywordAdGroupCriterion->adGroupId = $identifier;
$keywordAdGroupCriterion->criterion = $keywordobj;
$keywordAdGroupCriterionOperation = new AdGroupCriterionOperation();
$keywordAdGroupCriterionOperation->operand = $keywordAdGroupCriterion;
$keywordAdGroupCriterionOperation->operator = 'ADD';
$operations[] = $keywordAdGroupCriterionOperation;
}
$result = $adGroupCriterionService->mutate($operations);
This works fine. However, I've started to realise that doing such operations uses up API Units rather more quickly than I had anticipated. Is there a more API Unit friendly approach to doing this operation? Or is this simply the 'catch' with the Google Adwords API pricing?
해결책
Depending on how many keywords you're uploading at a time, you can use the MutateJobService; the coding is a little more complicated but you should save 50% of the unit cost.
다른 팁
If someone needs a quick code example, http://code.google.com/p/google-api-adwords-php/source/browse/trunk/examples/v201109/CampaignManagement/AddKeywordsInBulk.php shows how to use MutateJobService, it is much more simpler than the old BulkMutateJobService. Also, the original video from API workshop days is here, http://www.youtube.com/watch?v=CV_kOTW3ldQ, presentations here: https://sites.google.com/site/awapiworkshops/slides-and-links. Same links as JoeR posted, but linked to the original site this time.
For any AdWords API related questions, the official forum (http://groups.google.com/group/adwords-api) is the best place to ask questions. The group is very active, and Googlers from the API team regularly answer questions here.
Cheers, Anash