Beispiel #1
0
        /// <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);
            }
        }
Beispiel #2
0
        /// <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.v201502.AdGroupAdService);

            // Get all the disapproved ads for this campaign.
            string query = string.Format("SELECT Id, AdGroupAdDisapprovalReasons 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.disapprovalReasons)
                            {
                                Console.WriteLine("    {0}", reason);
                            }
                            i++;
                        }
                    }
                    offset += pageSize;
                } while (offset < page.totalNumEntries);
                Console.WriteLine("Number of disapproved ads found: {0}", page.totalNumEntries);
            } catch (Exception e) {
                throw new System.ApplicationException("Failed to get disapproved ads.", e);
            }
        }
Beispiel #3
0
        /// <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="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);
                }
            }
        }