Google.Api.Ads.AdWords.Examples.CSharp.v201306.UpdateCampaign.Run C# (CSharp) Méthode

Run() public méthode

Runs the code example.
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 updated.
Résultat void
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the CampaignService.
              CampaignService campaignService =
              (CampaignService)user.GetService(AdWordsService.v201306.CampaignService);

              // Create the campaign.
              Campaign campaign = new Campaign();
              campaign.id = campaignId;
              campaign.status = CampaignStatus.PAUSED;

              // Create the operation.
              CampaignOperation operation = new CampaignOperation();
              operation.@operator = Operator.SET;
              operation.operand = campaign;

              try {
            // Update the campaign.
            CampaignReturnValue retVal = campaignService.mutate((new CampaignOperation[] {operation}));

            // Display the results.
            if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
              Campaign updatedCampaign = retVal.value[0];
              Console.WriteLine("Campaign with name = '{0}' and id = '{1}' was updated.",
              updatedCampaign.name, updatedCampaign.id);
            } else {
              Console.WriteLine("No campaigns were updated.");
            }
              } catch (Exception ex) {
            throw new System.ApplicationException("Failed to update campaign.", 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)
 {
     UpdateCampaign codeExample = new UpdateCampaign();
       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));
       }
 }
UpdateCampaign