Our in-house AdWords Client will update keywords by removing them
first then create new ones, as I understand AdWords does not support
updating text of existing keywords.
The local database stores the Google keyword IDs when creating
keywords at AdWords. When deleting, the client will send Google
keyword IDs. From time to time, among 3,300 Google keyword IDs sent,
AdWords might complain around 10 of them as Invalid by returning
EntityNotFound error.
The codes of removing is like this:
public static bool RemoveKeywords(IEnumerable<KeywordItem>
items)
{
if (items == null)
return true;
if (items.Count() == 0)
return true;
List<AdGroupCriterionOperation> operations = new
List<AdGroupCriterionOperation>(items.Count());
foreach (KeywordItem item in items)
{
Keyword keyword = new Keyword();
keyword.id = item.Id;
keyword.idSpecified = true;
keyword.matchType = KeywordMatchType.PHRASE;
keyword.matchTypeSpecified = true;
keyword.text = "Anything for removing";
///The KeywordId is a 64-bit integer, and apparently
is a hash of the keyword text.
///While by priciple deleting a keyword needs only
AdGroupId and KeywordId, however,
///the API expects Keyword Match Type and Keyword
Text, which in fact can be anything
///without matching the keyword being deleted.
Apparently this is a flaw in the API.
AdGroupCriterion keywordCriterion = new
AdGroupCriterion();
keywordCriterion.AdGroupCriterionType = "Keyword";
keywordCriterion.criterion = keyword;
keywordCriterion.adGroupId = item.AdGroupId;
keywordCriterion.adGroupIdSpecified = true;
AdGroupCriterionOperation operation = new
AdGroupCriterionOperation();
operati...@operator = Operator.REMOVE;
operation.operatorSpecified = true;
operation.operand = keywordCriterion;
operations.Add(operation);
}
bool finalResult = false;
try
{
AdGroupCriterionService adGroupCriterionService =
(AdGroupCriterionService)GlobalSettings.Default.CurrentUser.GetService(AdWordsService.v200909.AdGroupCriterionService);
GlobalSettings.Default.APIUnitCostsOfCurrentCampaignOfSession +=
operations.Count * APIUnitCostsTable.AdGroupCriterion_Remove;
AdGroupCriterionReturnValue result =
adGroupCriterionService.mutate(
operations.ToArray());
if (result != null && result.value != null)
{
foreach (AdGroupCriterion adGroupCriterion in
result.value)
{
Trace.TraceInformation("Ad group criterion
with ad group id = '{0}, criterion id = '{1} " +
"and type = '{2}' was deleted.",
adGroupCriterion.adGroupId,
adGroupCriterion.criterion.id,
adGroupCriterion.criterion.CriterionType);
}
}
else
{
Trace.TraceWarning("No ad group criteria were
deleted.\n");
}
return true;
}
catch (AdWordsApiException ex)
{
ApiException e = ex.ApiException as ApiException;
List<long> idsInvalid = new List<long>();
foreach (ApiError error in e.errors)
{
EntityNotFound entityError = error as
EntityNotFound;
if (entityError != null)
{
Trace.TraceWarning("When RemoveKeywords:
Exception says \"{0}\". The trigger {1} in campaign {2} is in {3}.",
entityError.reason.ToString(),
entityError.trigger, GlobalSettings.Default.CurrentCampaignName,
error.fieldPath);
finalResult = true;//this is to resolve legacy
issue that the keyword was actually deleted sometime ago.
continue;
}
Trace.TraceWarning("When RemoveKeywords: Exception
says \"{0}\". The cause in campaign {1} is in {2}.", error.ToString(),
GlobalSettings.Default.CurrentCampaignName, error.fieldPath);
finalResult = false;
}
}
return finalResult;
}
And sometimes I got error log like this:
2010-07-30 17:08:04 Warning: When RemoveKeywords: Exception says
"INVALID_ID". The trigger 18626976346 in campaign Paul XYZ Automation
is in operations[1179].operand.criterion.id.
2010-07-30 17:08:04 Warning: When RemoveKeywords: Exception says
"INVALID_ID". The trigger 18627217666 in campaign Paul XYZ Automation
is in operations[1180].operand.criterion.id.
My questions are:
1. Are the C# codes above looking OK?
2. Is it possible to trace down the Google Keyword IDs at AdWords? And
how to avoid INVALID_ID error?
Many Thanks
Andy
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
http://adwordsapi.blogspot.com
http://groups.google.com/group/adwords-api
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en