4

I'm working with Google Adwords and currently can't get specific info. On my Adwords account I set 'IP address exclusion' with 3 IPs. I want to get this IPs 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 number of resuls: 3, but without actual info about ipAddress( ipAddress contains null) .

what can I do?

Stewart_R
  • 13,764
  • 11
  • 60
  • 106
Tsvi Girsh
  • 41
  • 1
  • 1
    Hi, don't have the solution to your question, but maybe you could easier debug your query with https://www.awql.me, a free tool to see the result of AWQL query. There is an online help and a helper to build the queries. – bastien Sep 25 '15 at 10:32
  • Thank you for your answer! I really appreciate for your suggestion. Currently, I've found a workaround for this problem and I work on another part of my development. Have a nice work! – Tsvi Girsh Sep 26 '15 at 18:59

1 Answers1

2

Unfortunately I do not believe that AWQL provides a selector for the Address of a blocked IP. In any case, it is certainly NOT supplied with the AWQL statement you have used above which is only bringing back the Id field:

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

This is why the value is null in your response.

The only way I believe it is possible is to get your hands dirty with the Selector and Predicate objects for that service and use the get() method rather than the query() one.

This solution works for me (admittedly with a later version of the 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);
}
Stewart_R
  • 13,764
  • 11
  • 60
  • 106