如何使用最新版本的 Google AdWords API 201509 删除单个附加链接并保留其余部分?

How do I delete a single sitelink using the newest version of Google AdWords API 201509 and leave the rest?

Google 添加了一种添加附加链接的新方法。

https://developers.google.com/adwords/api/docs/guides/extension-settings#add_ad_extensions

我加了一堆,怎么删啊?我在每个广告系列上都有 3 个附加链接。我能够从广告系列中删除一个附加链接,但它从广告系列中删除了 所有 个附加链接。它们仍在 + Extension 列表中,但未与任何活动相关联。

  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;
  }

好的,我 'fixed' 在删除目标附加链接后立即重新添加属于该广告系列的所有附加链接。我发誓,这是最弱智的部分API。

...
$result = $campaignExtensionSettingService->mutate($operations);

// now re-add the other sitelinks. the google API is removing/disassociating ALL sitelinks for whatever reason 
$operations = array();
foreach ($sitelinks as $sitelink) {
  $campaignSitelinks = array();
  $siblings = Sitelink::find()->where(['campaign_id' => $sitelink->campaign_id])->andWhere(['not', ['id' => $sitelink->id]])->all();
  foreach ($siblings as $sibling) {
    $sfi = new SitelinkFeedItem();
    $sfi->feedItemId = $sibling->google_feed_item_id;
    $campaignSitelinks[] = $sfi;
  }
  $campaignExtensionSetting = new CampaignExtensionSetting();
  $campaignExtensionSetting->campaignId = $sitelink->campaign->google_id;
  $campaignExtensionSetting->extensionType = 'SITELINK';
  $campaignExtensionSetting->extensionSetting = new ExtensionSetting();
  $campaignExtensionSetting->extensionSetting->extensions = $campaignSitelinks;
  // Create operation.
  $operation = new CampaignExtensionSettingOperation();
  $operation->operator = 'SET';
  $operation->operand = $campaignExtensionSetting;
  $operations[] = $operation;
}
$result = $campaignExtensionSettingService->mutate($operations);

// now remove all the sitelinks themselves
$feedItemService = $user->GetService('FeedItemService', ADWORDS_VERSION);
...