public Run ( Google.Api.Ads.AdWords.Lib.AdWordsUser user, long campaignId ) : void | ||
user | Google.Api.Ads.AdWords.Lib.AdWordsUser | The AdWords user. |
campaignId | long | Id of the campaign to be deleted. |
Результат | void |
public void Run(AdWordsUser user, long campaignId)
{
// Get the CampaignService.
CampaignService campaignService = (CampaignService) user.GetService(
AdWordsService.v201306.CampaignService);
// Create campaign with DELETED status.
Campaign campaign = new Campaign();
campaign.id = campaignId;
// When deleting a campaign, rename it to avoid name collisions with new
// campaigns.
campaign.name = "Deleted Campaign - " + ExampleUtilities.GetRandomString();
campaign.status = CampaignStatus.DELETED;
// Create the operation.
CampaignOperation operation = new CampaignOperation();
operation.operand = campaign;
operation.@operator = Operator.SET;
try {
// Delete the campaign.
CampaignReturnValue retVal = campaignService.mutate(new CampaignOperation[] {operation});
// Display the results.
if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
Campaign deletedCampaign = retVal.value[0];
Console.WriteLine("Campaign with id = \"{0}\" was renamed to \"{1}\" and deleted.",
deletedCampaign.id, deletedCampaign.name);
} else {
Console.WriteLine("No campaigns were deleted.");
}
} catch (Exception ex) {
throw new System.ApplicationException("Failed to delete campaign.", 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) { DeleteCampaign codeExample = new DeleteCampaign(); Console.WriteLine(codeExample.Description); try { long campaignId = long.Parse("INSERT_CAMPAIGN_ID_HERE"); codeExample.Run(new AdWordsUser(), campaignId); } catch (Exception ex) { Console.WriteLine("An exception occurred while running this code example. {0}", ExampleUtilities.FormatException(ex)); } }