I am trying to use GenerateKeywordIdeas method of KeywordPlanIdeaServiceClient service. It works fine if I send up to 20 keywords in the request. If I send more than 20 keywords the code breaks down. The error I am getting is
Status(StatusCode="InvalidArgument", Detail="Request contains an invalid argument.", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1648123856.780000000","description":"Error received from peer ipv4:
216.58.201.74:443","file":"......\src\core\lib\surface\call.cc","file_line":1070,"grpc_message":"Request contains an invalid argument.","grpc_status":3}")
I am using .Net Framework 4.7.2 and Google.Ads.GoogleAds 11.0.0.
Here is the code that I am using.
GoogleAdsConfig config = new GoogleAdsConfig()
{
DeveloperToken = "**************",
OAuth2ClientId = "**************",
OAuth2ClientSecret = "**************",
OAuth2RefreshToken = "**************"
};
GoogleAdsClient googleAdsClient = new GoogleAdsClient(config);
KeywordPlanIdeaServiceClient keywordPlanIdeaService = googleAdsClient.GetService(Services.V10.KeywordPlanIdeaService);
GenerateKeywordIdeasRequest request = new GenerateKeywordIdeasRequest()
{
CustomerId = "**************",
};
//Keywords
request.KeywordSeed = new KeywordSeed();
//Language
request.Language = ResourceNames.LanguageConstant(1000);
//Location
request.GeoTargetConstants.Add(ResourceNames.GeoTargetConstant(2840));
//Network
request.KeywordPlanNetwork = KeywordPlanNetwork.GoogleSearchAndPartners;
request.KeywordSeed.Keywords.AddRange(new string[] {
"ppc",
"sun",
"Moon",
"cold",
"night",
"table",
"golf",
"cat",
"dog",
"animal food",
"laptop",
"desktop",
"mouse",
"bat",
"hockey",
"net",
"shoe",
"knife",
"bag",
"battery",
"motorcycle",
"pin",
"chocolate"
});
try
{
var response = keywordPlanIdeaService.GenerateKeywordIdeas(request);
List<KeywordPlannerData> lstKeywordPlannerData = new List<KeywordPlannerData>();
foreach (GenerateKeywordIdeaResult result in response)
{
KeywordPlannerData keywordPlannerData = new KeywordPlannerData()
{
KeywordText = result.Text,
SearchVolume = (result.KeywordIdeaMetrics == null || !result.KeywordIdeaMetrics.HasAvgMonthlySearches) ? 0 : result.KeywordIdeaMetrics.AvgMonthlySearches,
Competition = (result.KeywordIdeaMetrics == null) ? "0" : result.KeywordIdeaMetrics.Competition.ToString(),
LowTopOfPageBid = (result.KeywordIdeaMetrics == null || !result.KeywordIdeaMetrics.HasLowTopOfPageBidMicros) ? 0 : (double)(result.KeywordIdeaMetrics.LowTopOfPageBidMicros) / 1000000,
HighTopOfPageBid = (result.KeywordIdeaMetrics == null || !result.KeywordIdeaMetrics.HasHighTopOfPageBidMicros) ? 0 : (double)(result.KeywordIdeaMetrics.HighTopOfPageBidMicros) / 1000000
};
lstKeywordPlannerData.Add(keywordPlannerData);
}
return lstKeywordPlannerData;
}
catch (GoogleAdsException e)
{
throw new System.ApplicationException("Failed to validate keywords.", e);
}