How can I get ipAddress information from a criterion?

I work with Google Adwords and currently cannot get specific information. On my Adwords account, I installed "IP Exclusion" with three IP addresses. I want to get these IP addresses from my code:

AdWordsUser user = new AdWordsUser();
var campaignService = (CampaignCriterionService)user.GetService(AdWordsService.v201506.CampaignCriterionService);
int offset = 0;
        int pageSize = 500;

        var page = new CampaignCriterionPage();
        String awql = "SELECT Id where IsNegative = true ORDER BY Id ASC LIMIT " + offset + "," + pageSize;
try
        {
            do
            {   
                page = campaignService.query(awql);

                // Display the results.
                if (page != null && page.entries != null)
                {
                    int i = offset;
                    foreach (var item in page.entries)
                    {
                        var t = item; //my work logic here ....                           
                        i++;
                    }
                }
                offset += pageSize;
            } while (offset < page.totalNumEntries);
            Debug.WriteLine("Number of items found: {0}", page.totalNumEntries);
        }
        catch (Exception e)
        {
            throw new System.ApplicationException("Failed to retrieve campaigns", e);
        }

Query returns a resuls: 3, but without actual ipAddress information (ipAddress contains null).

What can I do?

+4
source share
1 answer

Unfortunately, I do not think AWQL provides a selector for a blocked IP address. In any case, this, of course, does NOT come with the AWQL expression that you used above, which returns only the Id field:

String awql = "SELECT Id where IsNegative = true ORDER BY Id ASC LIMIT " + offset + "," + pageSize; try

null.

, , - Selector Predicate get(), query().

(, API)

var campaignCriterionService = (CampaignCriterionService)user.GetService(AdWordsService.v201601.CampaignCriterionService);
int offset = 0;
int pageSize = 500;

var page = new CampaignCriterionPage();

try
{
    do
    {
        page = campaignCriterionService.get(new Selector
        {
            fields = new string[] { IpBlock.Fields.Id, IpBlock.Fields.IpAddress },
            predicates = new Predicate[]
            {
                new Predicate
                {
                    field = IpBlock.Fields.CriteriaType,
                    @operator = PredicateOperator.EQUALS,
                    values = new string[] { "IP_BLOCK" }
                }
            }
        });

        // Display the results.
        if (page != null && page.entries != null)
        {
            int i = offset;
            foreach (var item in page.entries)
            {
                var t = item; //my work logic here ....                           
                i++;
            }
        }
        offset += pageSize;
    } while (offset < page.totalNumEntries);
    Debug.WriteLine("Number of items found: {0}", page.totalNumEntries);
}
catch (Exception e)
{
    throw new System.ApplicationException("Failed to retrieve campaigns", e);
}
+2

Source: https://habr.com/ru/post/1607982/


All Articles