Google added a new way to add sitelink extensions.
https://developers.google.com/adwords/api/docs/guides/extension-settings#add_ad_extensions
I added a bunch of them, but how do you delete them? I had 3 sitelinks on each campaign. I was able to remove a sitelink from the campaigns, but it removed all sitelinks from the campaigns. They are still in the + Extension
list, but not associated with any campaigns.
function deleteSitelinks($sitelinks) {
$user = $this->getUser();
$campaignExtensionSettingService = $user->GetService('CampaignExtensionSettingService', ADWORDS_VERSION);
// first remove the sitelinks from the campaigns
$operations = array();
foreach ($sitelinks as $sitelink) {
$sfi = new SitelinkFeedItem();
$sfi->feedItemId = $sitelink->google_feed_item_id;
$campaignExtensionSetting = new CampaignExtensionSetting();
$campaignExtensionSetting->campaignId = $sitelink->campaign->google_id;
$campaignExtensionSetting->extensionType = 'SITELINK';
$extensionSetting = new ExtensionSetting();
$extensionSetting->extensions = array($sfi);
$campaignExtensionSetting->extensionSetting = $extensionSetting;
$operation = new CampaignExtensionSettingOperation();
$operation->operator = 'REMOVE';
$operation->operand = $campaignExtensionSetting;
$operations[] = $operation;
}
$result = $campaignExtensionSettingService->mutate($operations);
// now remove the sitelinks themselves
$feedItemService = $user->GetService('FeedItemService', ADWORDS_VERSION);
$operations = array();
foreach ($sitelinks as $sitelink) {
$sfi = new SitelinkFeedItem();
$sfi->feedId = $sitelink->google_feed_id;
$sfi->feedItemId = $sitelink->google_feed_item_id;
$operation = new FeedItemOperation();
$operation->operator = 'REMOVE';
$operation->operand = $sfi;
$operations[] = $operation;
}
$result = $feedItemService->mutate($operations);
return $result->value;
}