// Get the TargetingIdeaService.
TargetingIdeaServiceInterface targetingIdeaService =
user.getService(AdWordsService.V201306.TARGETING_IDEA_SERVICE);
// 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);
// 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.setId(1000L);
languageParameter.setLanguages(new Language[] {english});
// Create related to query search parameter.
RelatedToQuerySearchParameter relatedToQuerySearchParameter =
new RelatedToQuerySearchParameter();
relatedToQuerySearchParameter.setQueries(new String[] {"mars cruise"});
selector.setSearchParameters(
new SearchParameter[] {relatedToQuerySearchParameter, languageParameter});
// Get related keywords.
TargetingIdeaPage page = targetingIdeaService.get(selector);