/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="adGroupId">ID of the ad group to use for generating ideas.</param> public void Run(AdWordsUser user, long?adGroupId) { using (TargetingIdeaService targetingIdeaService = (TargetingIdeaService)user.GetService(AdWordsService.v201710.TargetingIdeaService)) { // Create selector. TargetingIdeaSelector selector = new TargetingIdeaSelector(); selector.requestType = RequestType.IDEAS; selector.ideaType = IdeaType.KEYWORD; selector.requestedAttributeTypes = new AttributeType[] { AttributeType.KEYWORD_TEXT, AttributeType.SEARCH_VOLUME, AttributeType.AVERAGE_CPC, AttributeType.COMPETITION, AttributeType.CATEGORY_PRODUCTS_AND_SERVICES }; List <SearchParameter> searchParameters = new List <SearchParameter>(); // Create related to query search parameter. RelatedToQuerySearchParameter relatedToQuerySearchParameter = new RelatedToQuerySearchParameter(); relatedToQuerySearchParameter.queries = new String[] { "bakery", "pastries", "birthday cake" }; searchParameters.Add(relatedToQuerySearchParameter); // Add a language search parameter (optional). // The ID can be found in the documentation: // https://developers.google.com/adwords/api/docs/appendix/languagecodes LanguageSearchParameter languageParameter = new LanguageSearchParameter(); Language english = new Language(); english.id = 1000; languageParameter.languages = new Language[] { english }; searchParameters.Add(languageParameter); // Add network search parameter (optional). NetworkSetting networkSetting = new NetworkSetting(); networkSetting.targetGoogleSearch = true; networkSetting.targetSearchNetwork = false; networkSetting.targetContentNetwork = false; networkSetting.targetPartnerSearchNetwork = false; NetworkSearchParameter networkSearchParameter = new NetworkSearchParameter(); networkSearchParameter.networkSetting = networkSetting; searchParameters.Add(networkSearchParameter); // Optional: Use an existing ad group to generate ideas. if (adGroupId != null) { SeedAdGroupIdSearchParameter seedAdGroupIdSearchParameter = new SeedAdGroupIdSearchParameter(); seedAdGroupIdSearchParameter.adGroupId = adGroupId.Value; searchParameters.Add(seedAdGroupIdSearchParameter); } // Set the search parameters. selector.searchParameters = searchParameters.ToArray(); // Set selector paging (required for targeting idea service). selector.paging = Paging.Default; TargetingIdeaPage page = new TargetingIdeaPage(); try { int i = 0; do { // Get related keywords. page = targetingIdeaService.get(selector); // Display related keywords. if (page.entries != null && page.entries.Length > 0) { foreach (TargetingIdea targetingIdea in page.entries) { Dictionary <AttributeType, Google.Api.Ads.AdWords.v201710.Attribute> ideas = targetingIdea.data.ToDict(); string keyword = (ideas[AttributeType.KEYWORD_TEXT] as StringAttribute).value; IntegerSetAttribute categorySet = ideas[AttributeType.CATEGORY_PRODUCTS_AND_SERVICES] as IntegerSetAttribute; string categories = ""; if (categorySet != null && categorySet.value != null) { categories = string.Join(", ", categorySet.value); } long averageMonthlySearches = (ideas[AttributeType.SEARCH_VOLUME] as LongAttribute).value; Money averageCpc = (ideas[AttributeType.AVERAGE_CPC] as MoneyAttribute).value; double competition = (ideas[AttributeType.COMPETITION] as DoubleAttribute).value; Console.WriteLine("Keyword with text '{0}', average monthly search " + "volume {1}, average CPC {2}, and competition {3:F2} was found with " + "categories: {4}", keyword, averageMonthlySearches, averageCpc?.microAmount, competition, categories); Console.WriteLine("Keyword with text '{0}', and average monthly search volume " + "'{1}' was found with categories: {2}", keyword, averageMonthlySearches, categories); i++; } } selector.paging.IncreaseOffset(); } while (selector.paging.startIndex < page.totalNumEntries); Console.WriteLine("Number of related keywords found: {0}", page.totalNumEntries); } catch (Exception e) { throw new System.ApplicationException("Failed to retrieve related keywords.", e); } } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the TargetingIdeaService. TargetingIdeaService targetingIdeaService = (TargetingIdeaService) user.GetService(AdWordsService.v201509.TargetingIdeaService); string keywordText = "mars cruise"; // Create selector. TargetingIdeaSelector selector = new TargetingIdeaSelector(); selector.requestType = RequestType.IDEAS; selector.ideaType = IdeaType.KEYWORD; selector.requestedAttributeTypes = new AttributeType[] { AttributeType.KEYWORD_TEXT, AttributeType.SEARCH_VOLUME, AttributeType.CATEGORY_PRODUCTS_AND_SERVICES}; // Language setting (optional). // The ID can be found in the documentation: // https://developers.google.com/adwords/api/docs/appendix/languagecodes // Note: As of v201302, only a single language parameter is allowed. LanguageSearchParameter languageParameter = new LanguageSearchParameter(); Language english = new Language(); english.id = 1000; languageParameter.languages = new Language[] {english}; // Create related to query search parameter. RelatedToQuerySearchParameter relatedToQuerySearchParameter = new RelatedToQuerySearchParameter(); relatedToQuerySearchParameter.queries = new String[] {keywordText}; selector.searchParameters = new SearchParameter[] {relatedToQuerySearchParameter, languageParameter}; // Set selector paging (required for targeting idea service). Paging paging = Paging.Default; TargetingIdeaPage page = new TargetingIdeaPage(); try { int i = 0; do { // Get related keywords. page = targetingIdeaService.get(selector); // Display related keywords. if (page.entries != null && page.entries.Length > 0) { foreach (TargetingIdea targetingIdea in page.entries) { string keyword = null; string categories = null; long averageMonthlySearches = 0; foreach (Type_AttributeMapEntry entry in targetingIdea.data) { if (entry.key == AttributeType.KEYWORD_TEXT) { keyword = (entry.value as StringAttribute).value; } if (entry.key == AttributeType.CATEGORY_PRODUCTS_AND_SERVICES) { IntegerSetAttribute categorySet = entry.value as IntegerSetAttribute; StringBuilder builder = new StringBuilder(); if (categorySet.value != null) { foreach (int value in categorySet.value) { builder.AppendFormat("{0}, ", value); } categories = builder.ToString().Trim(new char[] {',', ' '}); } } if (entry.key == AttributeType.SEARCH_VOLUME) { averageMonthlySearches = (entry.value as LongAttribute).value; } } Console.WriteLine("Keyword with text '{0}', and average monthly search volume " + "'{1}' was found with categories: {2}", keyword, averageMonthlySearches, categories); i++; } } selector.paging.IncreaseOffset(); } while (selector.paging.startIndex < page.totalNumEntries); Console.WriteLine("Number of related keywords found: {0}", page.totalNumEntries); } catch (Exception e) { throw new System.ApplicationException("Failed to retrieve related keywords.", e); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the TargetingIdeaService. TargetingIdeaService targetingIdeaService = (TargetingIdeaService)user.GetService(AdWordsService.v201601.TargetingIdeaService); // Create selector. TargetingIdeaSelector selector = new TargetingIdeaSelector(); selector.requestType = RequestType.IDEAS; selector.ideaType = IdeaType.KEYWORD; selector.requestedAttributeTypes = new AttributeType[] { AttributeType.KEYWORD_TEXT, AttributeType.SEARCH_VOLUME, AttributeType.CATEGORY_PRODUCTS_AND_SERVICES }; // Create the search parameters. string keywordText = "mars cruise"; // Create related to query search parameter. RelatedToQuerySearchParameter relatedToQuerySearchParameter = new RelatedToQuerySearchParameter(); relatedToQuerySearchParameter.queries = new String[] { keywordText }; // Add a language search parameter (optional). // The ID can be found in the documentation: // https://developers.google.com/adwords/api/docs/appendix/languagecodes // Note: As of v201302, only a single language parameter is allowed. LanguageSearchParameter languageParameter = new LanguageSearchParameter(); Language english = new Language(); english.id = 1000; languageParameter.languages = new Language[] { english }; // Add network search parameter (optional). NetworkSetting networkSetting = new NetworkSetting(); networkSetting.targetGoogleSearch = true; networkSetting.targetSearchNetwork = false; networkSetting.targetContentNetwork = false; networkSetting.targetPartnerSearchNetwork = false; NetworkSearchParameter networkSearchParameter = new NetworkSearchParameter(); networkSearchParameter.networkSetting = networkSetting; // Set the search parameters. selector.searchParameters = new SearchParameter[] { relatedToQuerySearchParameter, languageParameter, networkSearchParameter }; // Set selector paging (required for targeting idea service). Paging paging = Paging.Default; TargetingIdeaPage page = new TargetingIdeaPage(); try { int i = 0; do { // Get related keywords. page = targetingIdeaService.get(selector); // Display related keywords. if (page.entries != null && page.entries.Length > 0) { foreach (TargetingIdea targetingIdea in page.entries) { string keyword = null; string categories = null; long averageMonthlySearches = 0; foreach (Type_AttributeMapEntry entry in targetingIdea.data) { if (entry.key == AttributeType.KEYWORD_TEXT) { keyword = (entry.value as StringAttribute).value; } if (entry.key == AttributeType.CATEGORY_PRODUCTS_AND_SERVICES) { IntegerSetAttribute categorySet = entry.value as IntegerSetAttribute; StringBuilder builder = new StringBuilder(); if (categorySet.value != null) { foreach (int value in categorySet.value) { builder.AppendFormat("{0}, ", value); } categories = builder.ToString().Trim(new char[] { ',', ' ' }); } } if (entry.key == AttributeType.SEARCH_VOLUME) { averageMonthlySearches = (entry.value as LongAttribute).value; } } Console.WriteLine("Keyword with text '{0}', and average monthly search volume " + "'{1}' was found with categories: {2}", keyword, averageMonthlySearches, categories); i++; } } selector.paging.IncreaseOffset(); } while (selector.paging.startIndex < page.totalNumEntries); Console.WriteLine("Number of related keywords found: {0}", page.totalNumEntries); } catch (Exception e) { throw new System.ApplicationException("Failed to retrieve related keywords.", e); } }
public string Get() { var user = new AdWordsUser(); using (TargetingIdeaService targetingIdeaService = (TargetingIdeaService)user.GetService(Google.Api.Ads.AdWords.Lib.AdWordsService.v201802.TargetingIdeaService)) { // Create selector. TargetingIdeaSelector selector = new TargetingIdeaSelector(); selector.requestType = RequestType.STATS; selector.ideaType = IdeaType.KEYWORD; selector.requestedAttributeTypes = new AttributeType[] { AttributeType.KEYWORD_TEXT, AttributeType.SEARCH_VOLUME }; List <SearchParameter> searchParameters = new List <SearchParameter>(); // Create related to query search parameter. RelatedToQuerySearchParameter relatedToQuerySearchParameter = new RelatedToQuerySearchParameter(); relatedToQuerySearchParameter.queries = new String[] { "bakery" }; searchParameters.Add(relatedToQuerySearchParameter); // Add a language search parameter (optional). // The ID can be found in the documentation: // https://developers.google.com/adwords/api/docs/appendix/languagecodes LanguageSearchParameter languageParameter = new LanguageSearchParameter(); Language english = new Language(); english.id = 1000; languageParameter.languages = new Language[] { english }; searchParameters.Add(languageParameter); // Add network search parameter (optional). NetworkSetting networkSetting = new NetworkSetting(); networkSetting.targetGoogleSearch = true; networkSetting.targetSearchNetwork = false; networkSetting.targetContentNetwork = false; networkSetting.targetPartnerSearchNetwork = false; NetworkSearchParameter networkSearchParameter = new NetworkSearchParameter(); networkSearchParameter.networkSetting = networkSetting; searchParameters.Add(networkSearchParameter); // Set the search parameters. selector.searchParameters = searchParameters.ToArray(); // Set selector paging (required for targeting idea service). Paging paging = Paging.Default; selector.paging = paging; TargetingIdeaPage page = new TargetingIdeaPage(); int i = 0; do { // Get related keywords. page = targetingIdeaService.get(selector); // Display related keywords. if (page.entries != null && page.entries.Length > 0) { foreach (var targetingIdea in page.entries) { Dictionary <AttributeType, Google.Api.Ads.AdWords.v201802.Attribute> ideas = targetingIdea.data.ToDict(); string keyword = (ideas[AttributeType.KEYWORD_TEXT] as StringAttribute).value; long averageMonthlySearches = (ideas[AttributeType.SEARCH_VOLUME] as LongAttribute).value; i++; } } selector.paging.IncreaseOffset(); } while (selector.paging.startIndex < page.totalNumEntries); } return("value"); }