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

Run() public method

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 for which disapproved ads /// are retrieved.
return void
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the AdGroupAdService.
              AdGroupAdService service =
              (AdGroupAdService) user.GetService(AdWordsService.v201306.AdGroupAdService);

              // Get all the disapproved ads for this campaign.
              string query = string.Format("SELECT Id, DisapprovalReasons WHERE CampaignId = {0} AND " +
              "AdGroupCreativeApprovalStatus = DISAPPROVED ORDER BY Id", campaignId);

              int offset = 0;
              int pageSize = 500;

              AdGroupAdPage page = new AdGroupAdPage();

              try {
            do {
              string queryWithPaging = string.Format("{0} LIMIT {1}, {2}", query, offset, pageSize);

              // Get the disapproved ads.
              page = service.query(queryWithPaging);

              // Display the results.
              if (page != null && page.entries != null) {
            int i = offset;
            foreach (AdGroupAd adGroupAd in page.entries) {
              Console.WriteLine("{0}) Ad id {1} has been disapproved for the following " +
                  "reason(s):", i, adGroupAd.ad.id);
              foreach (string reason in adGroupAd.ad.disapprovalReasons) {
                Console.WriteLine("    {0}", reason);
              }
              i++;
            }
              }
              offset += pageSize;
            } while (offset < page.totalNumEntries);
            Console.WriteLine("Number of disapproved ads found: {0}", page.totalNumEntries);
              } catch (Exception ex) {
            throw new System.ApplicationException("Failed to get disapproved ads.", 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)
 {
     GetAllDisapprovedAdsWithAwql codeExample = new GetAllDisapprovedAdsWithAwql();
       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));
       }
 }
GetAllDisapprovedAdsWithAwql