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);
}
}