/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign for which disapproved ads /// are retrieved.</param> public void Run(AdWordsUser user, long campaignId) { // Get the AdGroupAdService. AdGroupAdService service = (AdGroupAdService)user.GetService(AdWordsService.v201705.AdGroupAdService); // Create the selector. Selector selector = new Selector() { fields = new string[] { Ad.Fields.Id, AdGroupAd.Fields.PolicySummary }, predicates = new Predicate[] { Predicate.Equals(AdGroup.Fields.CampaignId, campaignId), }, paging = Paging.Default }; AdGroupAdPage page = new AdGroupAdPage(); int disapprovedAdsCount = 0; try { do { // Get the disapproved ads. page = service.get(selector); // Display the results. if (page != null && page.entries != null) { foreach (AdGroupAd adGroupAd in page.entries) { AdGroupAdPolicySummary policySummary = adGroupAd.policySummary; if (policySummary.combinedApprovalStatus != PolicyApprovalStatus.DISAPPROVED) { // Skip ad group ads that are not disapproved. continue; } disapprovedAdsCount++; Console.WriteLine("Ad with ID {0} and type '{1}' was disapproved with the " + "following policy topic entries: ", adGroupAd.ad.id, adGroupAd.ad.AdType); foreach (PolicyTopicEntry policyTopicEntry in policySummary.policyTopicEntries) { Console.WriteLine(" topic id: {0}, topic name: '{1}'", policyTopicEntry.policyTopicId, policyTopicEntry.policyTopicName); } } } selector.paging.IncreaseOffset(); } while (selector.paging.startIndex < page.totalNumEntries); Console.WriteLine("Number of disapproved ads found: {0}", disapprovedAdsCount); } catch (Exception e) { throw new System.ApplicationException("Failed to get disapproved ads.", e); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign for which disapproved ads /// are retrieved.</param> public void Run(AdWordsUser user, long campaignId) { // Get the AdGroupAdService. AdGroupAdService service = (AdGroupAdService)user.GetService(AdWordsService.v201705.AdGroupAdService); // Get all the disapproved ads for this campaign. string query = string.Format("SELECT Id, PolicySummary WHERE CampaignId = {0} ORDER BY Id", campaignId); int offset = 0; int pageSize = 500; AdGroupAdPage page = new AdGroupAdPage(); int disapprovedAdsCount = 0; 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) { foreach (AdGroupAd adGroupAd in page.entries) { AdGroupAdPolicySummary policySummary = adGroupAd.policySummary; if (policySummary.combinedApprovalStatus != PolicyApprovalStatus.DISAPPROVED) { // Skip ad group ads that are not disapproved. continue; } disapprovedAdsCount++; Console.WriteLine("Ad with ID {0} and type '{1}' was disapproved with the " + "following policy topic entries: ", adGroupAd.ad.id, adGroupAd.ad.AdType); foreach (PolicyTopicEntry policyTopicEntry in policySummary.policyTopicEntries) { Console.WriteLine(" topic id: {0}, topic name: '{1}'", policyTopicEntry.policyTopicId, policyTopicEntry.policyTopicName); } } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of disapproved ads found: {0}", disapprovedAdsCount); } catch (Exception e) { throw new System.ApplicationException("Failed to get disapproved ads.", e); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign for which disapproved ads /// are retrieved.</param> public void Run(AdWordsUser user, long campaignId) { using (AdGroupAdService adGroupAdService = (AdGroupAdService)user.GetService(AdWordsService.v201802.AdGroupAdService)) { // Create the selector. Selector selector = new Selector() { fields = new string[] { Ad.Fields.Id, AdGroupAd.Fields.PolicySummary }, predicates = new Predicate[] { Predicate.Equals(AdGroup.Fields.CampaignId, campaignId), Predicate.Equals(AdGroupAdPolicySummary.Fields.CombinedApprovalStatus, PolicyApprovalStatus.DISAPPROVED.ToString()) }, paging = Paging.Default }; AdGroupAdPage page = new AdGroupAdPage(); int disapprovedAdsCount = 0; try { do { // Get the disapproved ads. page = adGroupAdService.get(selector); // Display the results. if (page != null && page.entries != null) { foreach (AdGroupAd adGroupAd in page.entries) { AdGroupAdPolicySummary policySummary = adGroupAd.policySummary; disapprovedAdsCount++; Console.WriteLine("Ad with ID {0} and type '{1}' was disapproved with the " + "following policy topic entries: ", adGroupAd.ad.id, adGroupAd.ad.AdType); // Display the policy topic entries related to the ad disapproval. foreach (PolicyTopicEntry policyTopicEntry in policySummary.policyTopicEntries) { Console.WriteLine(" topic id: {0}, topic name: '{1}'", policyTopicEntry.policyTopicId, policyTopicEntry.policyTopicName); // Display the attributes and values that triggered the policy topic. if (policyTopicEntry.policyTopicEvidences != null) { foreach (PolicyTopicEvidence evidence in policyTopicEntry.policyTopicEvidences) { Console.WriteLine(" evidence type: {0}", evidence.policyTopicEvidenceType); if (evidence.evidenceTextList != null) { for (int i = 0; i < evidence.evidenceTextList.Length; i++) { Console.WriteLine(" evidence text[{0}]: {1}", i, evidence.evidenceTextList[i]); } } } } } } } selector.paging.IncreaseOffset(); } while (selector.paging.startIndex < page.totalNumEntries); Console.WriteLine("Number of disapproved ads found: {0}", disapprovedAdsCount); } catch (Exception e) { throw new System.ApplicationException("Failed to get disapproved ads.", e); } } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign for which disapproved ads /// are retrieved.</param> public void Run(AdWordsUser user, long campaignId) { using (AdGroupAdService adGroupAdService = (AdGroupAdService)user.GetService(AdWordsService.v201802.AdGroupAdService)) { // Get all the disapproved ads for this campaign. string query = string.Format("SELECT Id, PolicySummary WHERE CampaignId = {0} and " + "CombinedApprovalStatus = DISAPPROVED ORDER BY Id", campaignId); int offset = 0; int pageSize = 500; AdGroupAdPage page = new AdGroupAdPage(); int disapprovedAdsCount = 0; try { do { string queryWithPaging = string.Format("{0} LIMIT {1}, {2}", query, offset, pageSize); // Get the disapproved ads. page = adGroupAdService.query(queryWithPaging); // Display the results. if (page != null && page.entries != null) { foreach (AdGroupAd adGroupAd in page.entries) { AdGroupAdPolicySummary policySummary = adGroupAd.policySummary; disapprovedAdsCount++; Console.WriteLine("Ad with ID {0} and type '{1}' was disapproved with the " + "following policy topic entries: ", adGroupAd.ad.id, adGroupAd.ad.AdType); // Display the policy topic entries related to the ad disapproval. foreach (PolicyTopicEntry policyTopicEntry in policySummary.policyTopicEntries) { Console.WriteLine(" topic id: {0}, topic name: '{1}'", policyTopicEntry.policyTopicId, policyTopicEntry.policyTopicName); // Display the attributes and values that triggered the policy topic. if (policyTopicEntry.policyTopicEvidences != null) { foreach (PolicyTopicEvidence evidence in policyTopicEntry.policyTopicEvidences) { Console.WriteLine(" evidence type: {0}", evidence.policyTopicEvidenceType); if (evidence.evidenceTextList != null) { for (int i = 0; i < evidence.evidenceTextList.Length; i++) { Console.WriteLine(" evidence text[{0}]: {1}", i, evidence.evidenceTextList[i]); } } } } } } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of disapproved ads found: {0}", disapprovedAdsCount); } catch (Exception e) { throw new System.ApplicationException("Failed to get disapproved ads.", e); } } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The customer ID for which the call is made.</param> /// <param name="campaignId">Id of the campaign for which disapproved ads /// are retrieved.</param> public void Run(GoogleAdsClient client, long customerId, long campaignId) { // Get the GoogleAdsService. GoogleAdsServiceClient googleAdsService = client.GetService( Services.V5.GoogleAdsService); string searchQuery = $@" SELECT ad_group_ad.ad.id, ad_group_ad.ad.type, ad_group_ad.policy_summary.approval_status, ad_group_ad.policy_summary.policy_topic_entries FROM ad_group_ad WHERE campaign.id = {campaignId} AND ad_group_ad.policy_summary.approval_status = DISAPPROVED"; // Create a request that will retrieve all Disapproved Ads SearchGoogleAdsRequest request = new SearchGoogleAdsRequest() { PageSize = PAGE_SIZE, Query = searchQuery, CustomerId = customerId.ToString(), ReturnTotalResultsCount = true }; try { // Issue the search request. PagedEnumerable <SearchGoogleAdsResponse, GoogleAdsRow> searchPagedResponse = googleAdsService.Search(request); long disapprovedAdsCount = searchPagedResponse.AsRawResponses() .First().TotalResultsCount; // Iterate over all rows in all rows returned and count disapproved Ads foreach (GoogleAdsRow googleAdsRow in searchPagedResponse) { AdGroupAdPolicySummary policySummary = googleAdsRow.AdGroupAd.PolicySummary; AdGroupAd adGroupAd = googleAdsRow.AdGroupAd; Ad ad = adGroupAd.Ad; Console.WriteLine( "Ad with ID {0} and type '{1}' was disapproved with the " + "following policy topic entries: ", ad.Id, ad.Type); // Display the policy topic entries related to the ad disapproval. foreach (PolicyTopicEntry policyTopicEntry in policySummary.PolicyTopicEntries) { Console.WriteLine(" topic: {0}, type: '{1}'", policyTopicEntry.Topic, policyTopicEntry.Type); // Display the attributes and values that triggered the policy topic. if (policyTopicEntry.Evidences != null) { foreach (PolicyTopicEvidence evidence in policyTopicEntry.Evidences) { if (evidence.TextList != null) { for (int i = 0; i < evidence.TextList.Texts.Count; i++) { Console.WriteLine(" evidence text[{0}]: {1}", i, evidence.TextList.Texts[i]); } } } } } } Console.WriteLine("Number of disapproved ads found: {0}", disapprovedAdsCount); } catch (GoogleAdsException e) { Console.WriteLine("Failure:"); Console.WriteLine($"Message: {e.Message}"); Console.WriteLine($"Failure: {e.Failure}"); Console.WriteLine($"Request ID: {e.RequestId}"); throw; } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign for which disapproved ads /// are retrieved.</param> public void Run(AdWordsUser user, long campaignId) { using (AdGroupAdService adGroupAdService = (AdGroupAdService)user.GetService(AdWordsService.v201802.AdGroupAdService)) { // Get all the disapproved ads for this campaign. SelectQuery query = new SelectQueryBuilder() .Select(Ad.Fields.Id, AdGroupAd.Fields.PolicySummary) .Where(AdGroup.Fields.CampaignId).Equals(campaignId) .Where(AdGroupAdPolicySummary.Fields.CombinedApprovalStatus) .Equals(ApprovalStatus.DISAPPROVED.ToString()) .OrderByAscending(Ad.Fields.Id) .DefaultLimit() .Build(); AdGroupAdPage page = new AdGroupAdPage(); int disapprovedAdsCount = 0; try { do { // Get the disapproved ads. page = adGroupAdService.query(query); // Display the results. if (page != null && page.entries != null) { foreach (AdGroupAd adGroupAd in page.entries) { AdGroupAdPolicySummary policySummary = adGroupAd.policySummary; disapprovedAdsCount++; Console.WriteLine( "Ad with ID {0} and type '{1}' was disapproved with the " + "following policy topic entries: ", adGroupAd.ad.id, adGroupAd.ad.AdType); // Display the policy topic entries related to the ad disapproval. foreach (PolicyTopicEntry policyTopicEntry in policySummary .policyTopicEntries) { Console.WriteLine(" topic id: {0}, topic name: '{1}'", policyTopicEntry.policyTopicId, policyTopicEntry.policyTopicName); // Display the attributes and values that triggered the policy // topic. if (policyTopicEntry.policyTopicEvidences != null) { foreach (PolicyTopicEvidence evidence in policyTopicEntry .policyTopicEvidences) { Console.WriteLine(" evidence type: {0}", evidence.policyTopicEvidenceType); if (evidence.evidenceTextList != null) { for (int i = 0; i < evidence.evidenceTextList.Length; i++) { Console.WriteLine( " evidence text[{0}]: {1}", i, evidence.evidenceTextList[i]); } } } } } } } query.NextPage(page); } while (query.HasNextPage(page)); Console.WriteLine("Number of disapproved ads found: {0}", disapprovedAdsCount); } catch (Exception e) { throw new System.ApplicationException("Failed to get disapproved ads.", e); } } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The customer ID for which the call is made.</param> /// <param name="campaignId">Id of the campaign for which disapproved ads /// are retrieved.</param> public void Run(GoogleAdsClient client, long customerId, long campaignId) { // Get the GoogleAdsService. GoogleAdsServiceClient googleAdsService = client.GetService( Services.V2.GoogleAdsService); String searchQuery = $@"SELECT ad_group_ad.ad.id, ad_group_ad.ad.type, ad_group_ad.policy_summary FROM ad_group_ad WHERE campaign.id = {campaignId}"; // Create a request that will retrieve all Disapproved Ads SearchGoogleAdsRequest request = new SearchGoogleAdsRequest() { PageSize = PAGE_SIZE, Query = searchQuery, CustomerId = customerId.ToString() }; int disapprovedAdsCount = 0; try { // Issue the search request. PagedEnumerable <SearchGoogleAdsResponse, GoogleAdsRow> searchPagedResponse = googleAdsService.Search(request); // Iterate over all rows in all rows returned and count disapproved Ads foreach (GoogleAdsRow googleAdsRow in searchPagedResponse) { AdGroupAdPolicySummary policySummary = googleAdsRow.AdGroupAd.PolicySummary; AdGroupAd adGroupAd = googleAdsRow.AdGroupAd; Ad ad = adGroupAd.Ad; if (adGroupAd.PolicySummary.ApprovalStatus != PolicyApprovalStatus.Disapproved) { continue; } disapprovedAdsCount++; Console.WriteLine( "Ad with ID {0} and type '{1}' was disapproved with the " + "following policy topic entries: ", ad.Id, ad.Type); // Display the policy topic entries related to the ad disapproval. foreach (PolicyTopicEntry policyTopicEntry in policySummary.PolicyTopicEntries) { Console.WriteLine(" topic: {0}, type: '{1}'", policyTopicEntry.Topic, policyTopicEntry.Type); // Display the attributes and values that triggered the policy topic. if (policyTopicEntry.Evidences != null) { foreach (PolicyTopicEvidence evidence in policyTopicEntry.Evidences) { if (evidence.TextList != null) { for (int i = 0; i < evidence.TextList.Texts.Count; i++) { Console.WriteLine(" evidence text[{0}]: {1}", i, evidence.TextList.Texts[i]); } } } } } } Console.WriteLine("Number of disapproved ads found: {0}", disapprovedAdsCount); } catch (Exception e) { throw new System.ApplicationException("Failed to get disapproved ads.", e); } }
public IEnumerable <GetAdsResponse> GetAllApprovedAds(AdWordsUser user, long campaignId) { var result = new List <GetAdsResponse>(); using (AdGroupAdService adGroupAdService = (AdGroupAdService)user.GetService(AdWordsService.v201802.AdGroupAdService)) { try { // Create the selector. Selector selector = new Selector() { fields = new string[] { Ad.Fields.Id, AdGroupAd.Fields.PolicySummary }, predicates = new Predicate[] { Predicate.Equals(AdGroup.Fields.CampaignId, campaignId), Predicate.Equals(AdGroupAdPolicySummary.Fields.CombinedApprovalStatus, PolicyApprovalStatus.APPROVED.ToString()) }, paging = Paging.Default }; AdGroupAdPage page = new AdGroupAdPage(); int approvedAdsCount = 0; page = adGroupAdService.get(selector); if (page.entries != null) { foreach (AdGroupAd adGroupAd in page.entries) { AdGroupAdPolicySummary policySummary = adGroupAd.policySummary; approvedAdsCount++; result.Add(new GetAdsResponse { AdId = adGroupAd.ad.id, AdHeadings = adGroupAd.ad.displayUrl }); } } else { //Test Account result.Add(new GetAdsResponse { AdId = 2, AdHeadings = "Heading Sample 2" }); result.Add(new GetAdsResponse { AdId = 3, AdHeadings = "Heading Sample 3" }); } } catch (Exception x) { throw new Exception(x.Message); } return(result); } }