我正在使用Google Adwords,目前无法获取具体信息。在我的Adwords帐户中,我设置了3个IP的“IP地址排除”。我想从我的代码中获取这些IP:
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);
}
查询返回结果数:3,但没有关于ipAddress的实际信息(ipAddress包含null)。
我该怎么办?
答案 0 :(得分:2)
不幸的是,我不相信AWQL为被阻止的IP的地址提供了一个选择器。在任何情况下,它肯定不会提供您上面使用的AWQL语句,它只返回Id字段:
String awql = "SELECT Id where IsNegative = true ORDER BY Id ASC LIMIT " + offset + "," + pageSize; try
这就是您的回复中值为空的原因。
我认为可能的唯一方法是弄清楚该服务的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);
}