// Get the TargetingIdeaService.
TargetingIdeaServiceInterface targetingIdeaService =
adWordsServices.get(session, TargetingIdeaServiceInterface.class);
// Create selector.
TargetingIdeaSelector selector = new TargetingIdeaSelector();
selector.setRequestType(RequestType.IDEAS);
selector.setIdeaType(IdeaType.KEYWORD);
selector.setRequestedAttributeTypes(new AttributeType[] {
AttributeType.KEYWORD_TEXT,
AttributeType.SEARCH_VOLUME,
AttributeType.CATEGORY_PRODUCTS_AND_SERVICES});
// Set selector paging (required for targeting idea service).
Paging paging = new Paging();
paging.setStartIndex(0);
paging.setNumberResults(10);
selector.setPaging(paging);
// Create related to query search parameter.
RelatedToQuerySearchParameter relatedToQuerySearchParameter =
new RelatedToQuerySearchParameter();
relatedToQuerySearchParameter.setQueries(new String[] {"mars cruise"});
// Language setting (optional).
// The ID can be found in the documentation:
// https://developers.google.com/adwords/api/docs/appendix/languagecodes
// See the documentation for limits on the number of allowed language parameters:
// https://developers.google.com/adwords/api/docs/reference/latest/TargetingIdeaService.LanguageSearchParameter
LanguageSearchParameter languageParameter = new LanguageSearchParameter();
Language english = new Language();
english.setId(1000L);
languageParameter.setLanguages(new Language[] {english});
selector.setSearchParameters(
new SearchParameter[] {relatedToQuerySearchParameter, languageParameter});
// Get related keywords.
TargetingIdeaPage page = targetingIdeaService.get(selector);