我正在尝试使用Google Adwords API关键字搜索计划器(Java)获得某个关键字的搜索量(每月平均)排名前5位的城市。
我有下面的代码,它正在尝试返回平均每月搜索量,但是我不确定是否可以返回有关该平均值的地理位置统计信息。示例(伦敦:444,曼彻斯特,999..etc)。
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session,@Nullable Long adGroupId) throws RemoteException
{
// Get the TargetingIdeaService.
TargetingIdeaServiceInterface targetingIdeaService = adWordsServices.get(session,
TargetingIdeaServiceInterface.class);
// Create selector.
TargetingIdeaSelector selector = new TargetingIdeaSelector();
selector.setRequestType(RequestType.STATS);
selector.setIdeaType(IdeaType.KEYWORD);
selector.setRequestedAttributeTypes(
new AttributeType[] { AttributeType.KEYWORD_TEXT, AttributeType.SEARCH_VOLUME });
// Countrycodes
// http://code.google.com/apis/adwords/docs/appendix/countrycodes.html
Location location = new Location();
location.setId(2826L);
// Set selector paging (required for targeting idea service).
Paging paging = new Paging();
paging.setStartIndex(0);
paging.setNumberResults(10);
selector.setPaging(paging);
List searchParameters = new ArrayList();
// Create related to query search parameter.
RelatedToQuerySearchParameter relatedToQuerySearchParameter = new RelatedToQuerySearchParameter();
relatedToQuerySearchParameter.setQueries(new String[] { "Football" });
searchParameters.add(relatedToQuerySearchParameter);
LocationSearchParameter locationSearchParameter = new LocationSearchParameter();
locationSearchParameter.setLocations(new Location[] { location });
// 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 });
searchParameters.add(languageParameter);
searchParameters.add(locationSearchParameter);
selector.setSearchParameters(searchParameters.toArray(new SearchParameter[searchParameters.size()]));
// Get keyword ideas.
TargetingIdeaPage page = targetingIdeaService.get(selector);
// Display keyword ideas.
for (TargetingIdea targetingIdea : page.getEntries()) {
Map data = Maps.toMap(targetingIdea.getData());
StringAttribute keyword = (StringAttribute) data.get(AttributeType.KEYWORD_TEXT);
Long averageMonthlySearches = ((LongAttribute) data.get(AttributeType.SEARCH_VOLUME)).getValue();
System.out.printf("Keyword with text '%s', average monthly search volume %d, ", keyword.getValue(),
averageMonthlySearches);
}
if (page.getEntries() == null) {
System.out.println("No related keywords were found.");
}
}
上面的代码输出是:
Keyword with text 'Football', average monthly search volume 4343,