Read the code below : I noticed that KeywordToolExternal changes the
order of inputs and sorts them by relevancy. Guess what , same thing
happens when i want to get same data through API. and best part is
there is no way i can map back the results to Keywords. So if i want
to get the stats in bulk then i cant use it.
public class AdWords2009 {
public static void main(String args[]) throws IOException,
ServiceException {
Keyword kw1 = new Keyword();
kw1.setText("silver shoes");
kw1.setMatchType(KeywordMatchType.EXACT);
Keyword kw2 = new Keyword();
kw2.setText("black shoes");
kw2.setMatchType(KeywordMatchType.EXACT);
Keyword kw3 = new Keyword();
kw3.setText("Leather rain boots");
kw3.setMatchType(KeywordMatchType.EXACT);
System.out.println("===one keyword at a time with STATS===");
printStats(new Keyword[]{kw1}, RequestType.STATS);
printStats(new Keyword[]{kw2}, RequestType.STATS);
printStats(new Keyword[]{kw3}, RequestType.STATS);
System.out.println("===ALL keywords at a time with STATS===");
printStats(new Keyword[]{kw1, kw2, kw3}, RequestType.STATS);
}
public static void printStats(Keyword kw[], RequestType rt) throws
RemoteException, ServiceException {
Map<String, String> credentials = new HashMap<String, String>();
credentials.put("email", SEMConstants.ADWORDS_EMAIL);
credentials.put("password", SEMConstants.ADWORDS_PASSWD);
credentials.put("useragent", SEMConstants.ADWORDS_USER_AGENT);
credentials.put("developerToken",
SEMConstants.ADWORDS_DEVELOPER_TOKEN);
credentials.put("applicationToken",
SEMConstants.ADWORDS_APPLICATION_TOKEN);
credentials.put("version", "v200909");
credentials.put("alternateUrl", "https://adwords.google.com");
credentials.put("clientId", "...");
AdWordsUser adWordsUser = new AdWordsUser(credentials);
adWordsUser.setAuthToken("...");
TargetingIdeaServiceInterface tisi =
(TargetingIdeaServiceInterface)
adWordsUser.getService(AdWordsService.V200909.TARGETING_IDEA_SERVICE);
TargetingIdeaSelector tis = new TargetingIdeaSelector();
tis.setIdeaType(IdeaType.KEYWORD);
tis.setRequestType(rt);
RelatedToKeywordSearchParameter sp1 = new
RelatedToKeywordSearchParameter();
KeywordMatchTypeSearchParameter sp2 = new
KeywordMatchTypeSearchParameter(null, new KeywordMatchType[]
{KeywordMatchType.EXACT});
AttributeType at[] = new AttributeType[]
{AttributeType.TARGETED_MONTHLY_SEARCHES};
CountryTargetSearchParameter sp3 = new
CountryTargetSearchParameter();
CountryTarget ct = new CountryTarget();
ct.setCountryCode("US");
sp3.setCountryTargets(new CountryTarget[]{ct});
tis.setRequestedAttributeTypes(at);
tis.setLocaleCode("en_US");
tis.setCurrencyCode("USD");
tis.setPaging(new Paging(0, 100));
sp1.setKeywords(kw);
tis.setSearchParameters(new SearchParameter[]{sp1, sp2, sp3});
int index = 0;
TargetingIdeaPage result = tisi.get(tis);
for (TargetingIdea tip : result.getEntries()) {
Type_AttributeMapEntry map[] = tip.getData();
for (Type_AttributeMapEntry ta : map) {
MonthlySearchVolumeAttribute msva =
(MonthlySearchVolumeAttribute)
ta.getValue();
MonthlySearchVolume msv[] = msva.getValue();
Long inorder[] = new Long[12];
for (MonthlySearchVolume m : msv) {
if (m.getMonth() != null &&
m.getCount() != null) {
inorder[m.getMonth() - 1] =
m.getCount();
}
}
System.out.println(kw[index++].getText() + ","
+ inorder[0] + ","
+ inorder[1] + "," + inorder[2] + "," + inorder[3] + "," + inorder[4]
+ ","
+ inorder[5] + "," + inorder[6]
+ "," + inorder[7] + "," +
inorder[8] + "," + inorder[9] + "," + inorder[10] + "," +
inorder[11]);
}
}
}
}
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Have you migrated to v200909 yet?
The v13 sunset is on April 22, 2010.
Also find us on our blog and discussion group:
http://adwordsapi.blogspot.com
http://groups.google.com/group/adwords-api
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en