public Run ( Google.Api.Ads.AdWords.Lib.AdWordsUser user, long adGroupId ) : void | ||
user | Google.Api.Ads.AdWords.Lib.AdWordsUser | The AdWords user. |
adGroupId | long | Id of the ad group to be deleted. |
Résultat | void |
public void Run(AdWordsUser user, long adGroupId)
{
// Get the AdGroupService.
AdGroupService adGroupService = (AdGroupService) user.GetService(
AdWordsService.v201306.AdGroupService);
// Create ad group with DELETED status.
AdGroup adGroup = new AdGroup();
adGroup.id = adGroupId;
// When deleting an ad group, rename it to avoid name collisions with new
// adgroups.
adGroup.name = "Deleted AdGroup - " + ExampleUtilities.GetRandomString();
adGroup.status = AdGroupStatus.DELETED;
// Create the operation.
AdGroupOperation operation = new AdGroupOperation();
operation.operand = adGroup;
operation.@operator = Operator.SET;
try {
// Delete the ad group.
AdGroupReturnValue retVal = adGroupService.mutate(new AdGroupOperation[] {operation});
// Display the results.
if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
AdGroup deletedAdGroup = retVal.value[0];
Console.WriteLine("Ad group with id = \"{0}\" was renamed to \"{1}\" and deleted.",
deletedAdGroup.id, deletedAdGroup.name);
} else {
Console.WriteLine("No ad groups were deleted.");
}
} catch (Exception ex) {
throw new System.ApplicationException("Failed to delete ad group.", ex);
}
}
/// <summary> /// Main method, to run this code example as a standalone application. /// </summary> /// <param name="args">The command line arguments.</param> public static void Main(string[] args) { DeleteAdGroup codeExample = new DeleteAdGroup(); Console.WriteLine(codeExample.Description); try { long adGroupId = long.Parse("INSERT_ADGROUP_ID_HERE"); codeExample.Run(new AdWordsUser(), adGroupId); } catch (Exception ex) { Console.WriteLine("An exception occurred while running this code example. {0}", ExampleUtilities.FormatException(ex)); } }