Google.Api.Ads.AdWords.Examples.CSharp.v201306.DeleteKeyword.Run C# (CSharp) Method

Run() public method

Runs the code example.
public Run ( Google.Api.Ads.AdWords.Lib.AdWordsUser user, long adGroupId, long keywordId ) : void
user Google.Api.Ads.AdWords.Lib.AdWordsUser The AdWords user.
adGroupId long Id of the ad group that contains the keyword. ///
keywordId long Id of the keyword to be deleted.
return void
        public void Run(AdWordsUser user, long adGroupId, long keywordId)
        {
            // Get the AdGroupCriterionService.
              AdGroupCriterionService adGroupCriterionService = (AdGroupCriterionService)user.GetService(
              AdWordsService.v201306.AdGroupCriterionService);

              // Create base class criterion to avoid setting keyword-specific fields.
              Criterion criterion = new Criterion();
              criterion.id = keywordId;

              // Create the ad group criterion.
              BiddableAdGroupCriterion adGroupCriterion = new BiddableAdGroupCriterion();
              adGroupCriterion.adGroupId = adGroupId;
              adGroupCriterion.criterion = criterion;

              // Create the operation.
              AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
              operation.operand = adGroupCriterion;
              operation.@operator = Operator.REMOVE;

              try {
            // Delete the keyword.
            AdGroupCriterionReturnValue retVal = adGroupCriterionService.mutate(
            new AdGroupCriterionOperation[] {operation});

            // Display the results.
            if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
              AdGroupCriterion deletedKeyword = retVal.value[0];
              Console.WriteLine("Keyword with ad group id = \"{0}\" and id = \"{1}\" was deleted.",
              deletedKeyword.adGroupId, deletedKeyword.criterion.id);
            } else {
              Console.WriteLine("No keywords were deleted.");
            }
              } catch (Exception ex) {
            throw new System.ApplicationException("Failed to delete keyword.", ex);
              }
        }

Usage Example

 /// <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)
 {
     DeleteKeyword codeExample = new DeleteKeyword();
       Console.WriteLine(codeExample.Description);
       try {
     long adGroupId = long.Parse("INSERT_ADGROUP_ID_HERE");
     long keywordId = long.Parse("INSERT_KEYWORD_ID_HERE");
     codeExample.Run(new AdWordsUser(), adGroupId, keywordId);
       } catch (Exception ex) {
     Console.WriteLine("An exception occurred while running this code example. {0}",
     ExampleUtilities.FormatException(ex));
       }
 }
DeleteKeyword