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

Run() public method

Runs the code example.
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 updated.
return void
        public void Run(AdWordsUser user, long adGroupId)
        {
            // Get the AdGroupService.
              AdGroupService adGroupService =
              (AdGroupService) user.GetService(AdWordsService.v201306.AdGroupService);

              // Create the ad group.
              AdGroup adGroup = new AdGroup();
              adGroup.status = AdGroupStatus.PAUSED;
              adGroup.id = adGroupId;

              // Create the operation.
              AdGroupOperation operation = new AdGroupOperation();
              operation.@operator = Operator.SET;
              operation.operand = adGroup;

              try {
            // Update the ad group.
            AdGroupReturnValue retVal = adGroupService.mutate(new AdGroupOperation[] {operation});

            // Display the results.
            if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
              AdGroup pausedAdGroup = retVal.value[0];
              Console.WriteLine("Ad group with id = '{0}' was successfully updated.",
              pausedAdGroup.id);
            } else {
              Console.WriteLine("No ad groups were updated.");
            }
              } catch (Exception ex) {
            throw new System.ApplicationException("Failed to update ad group.", 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)
 {
     UpdateAdGroup codeExample = new UpdateAdGroup();
       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));
       }
 }
UpdateAdGroup