【发布时间】:2018-04-13 10:31:09
【问题描述】:
我正在尝试通过 CampaignCriterionService 添加一个否定关键字,该关键字是从特定广告系列的 SearchTerms 报告中检索到的。
我有可以将否定关键字添加到广告系列的工作代码,太好了。问题来自关键字文本包含“特殊字符”(see here)的位置
错误:
关键字文本包含无效字符或符号..(错误:CriterionError.KEYWORD_HAS_INVALID_CHARS,FieldPath:操作[0].operand.criterion.text,触发器:普通镜像100 * 60)
我从搜索字词报告中提取了关键字,它有一个关键字 ID。因此,我尝试使用以下关键字将关键字添加为否定关键字
示例:
using Google.Api.Ads.AdWords.Lib;
using Google.Api.Ads.AdWords.Util.Reports.v201802;
using Google.Api.Ads.AdWords.v201802;
[TestMethod]
public void AddSingleNegativeKeywordToCampaign()
{
GoogleAdwords.Model.Campaign campaign = new GoogleAdwords.Model.Campaign(CampaignID);
List<Keyword> keywords = new List<Keyword> { new Keyword { id = 27736878000, matchType = KeywordMatchType.EXACT } };
campaign.AddNegativeKeywordstoCampaign(keywords);
}
public class Campaign : AdwordsBase
{
public long CampaignId { get; set; }
public string CampaignName;
public Campaign(long campaignId) : base()
{
CampaignId = campaignId;
}
public void AddNegativeKeywordstoCampaign(List<Keyword> ListofKeywords)
{
AddKeywordstoCampaign(ListofKeywords, Operator.ADD);
}
private void AddKeywordstoCampaign(List<Keyword> keywords, Operator @operator)
{
using (CampaignCriterionService campaignCriterionService =
(CampaignCriterionService)user.GetService(
AdWordsService.v201802.CampaignCriterionService))
{
List<CampaignCriterionOperation> operations = new List<CampaignCriterionOperation>();
foreach (Keyword keyword in keywords)
{
// Create the biddable ad group criterion.
NegativeCampaignCriterion keywordCriterion = new NegativeCampaignCriterion();
keywordCriterion.campaignId = CampaignId;
keywordCriterion.criterion = keyword;
// Create the operations.
CampaignCriterionOperation operation = new CampaignCriterionOperation();
operation.@operator = @operator;
operation.operand = keywordCriterion;
operations.Add(operation);
}
try
{
// Create the keywords.
CampaignCriterionReturnValue retVal = campaignCriterionService.mutate(
operations.ToArray());
// Display the results.
if (retVal != null && retVal.value != null)
{
foreach (CampaignCriterion campaignCriterion in retVal.value)
{
// If you are adding multiple type of criteria, then you may need to
// check for
//
// if (adGroupCriterion is Keyword) { ... }
//
// to identify the criterion type.
Debug.WriteLine("Keyword with Campaign id = '{0}', keyword id = '{1}', text = " +
"'{2}' and match type = '{3}' was {4}.", campaignCriterion.campaignId,
campaignCriterion.criterion.id, (campaignCriterion.criterion as Keyword).text,
(campaignCriterion.criterion as Keyword).matchType, @operator.ToString());
}
}
else
{
Debug.WriteLine("No keywords were added.");
}
}
catch (Exception e)
{
throw new System.ApplicationException("Failed to create keywords.", e);
}
}
}
}
但是这不起作用,因为 api 报告错误:
缺少必填字段..(错误:RequiredError.REQUIRED,FieldPath:操作[0].operand.criterion.text,触发器:)
我的问题是
我可以在 Adwords UI 中将搜索词添加为否定词,因此,它一定是可能的。有没有人能够使用最新版本的 Adwords API 实现这一目标? (v201802)
说得很清楚,我认为代码本身没有任何问题,更多的是关于如何添加属于此职权范围的关键字的问题。
【问题讨论】:
-
我无法在 UI 中将“普通镜子 100 * 60”添加为否定关键字,既没有直接添加到广告系列中,也没有添加到否定关键字列表中。错误总是 “关键字不能包含非标准字符,例如:!@ % , *”。这对你真的有用吗?
-
抱歉,我以为我可以,但实际上我似乎做不到。
标签: c# google-api google-ads-api google-api-dotnet-client