gpt4 book ai didi

c# - 如何从标准中获取 ip 地址信息?

转载 作者:行者123 更新时间:2023-11-30 12:24:56 25 4
gpt4 key购买 nike

我正在使用 Google Adwords,目前无法获取具体信息。在我的 Adwords 帐户上,我将“IP 地址排除”设置为 3 个 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)。

我能做什么?

最佳答案

不幸的是,我不相信 AWQL 会为被阻止的 IP 地址提供选择器。在任何情况下,它肯定不会随您在上面使用的 AWQL 语句一起提供,该语句只会带回 Id 字段:

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

这就是您的响应中值为空的原因。

我认为唯一可行的方法是亲自动手为该服务使用 SelectorPredicate 对象,并使用 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);
}

关于c# - 如何从标准中获取 ip 地址信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32647758/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com