TargetingIdeaService - This is so lame - Please help to fix it

24 views
Skip to first unread message

arastogi

unread,
Mar 11, 2010, 5:35:04 PM3/11/10
to AdWords API Forum
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]);
}

}

}

}


AdWords API Advisor

unread,
Mar 12, 2010, 4:15:56 PM3/12/10
to AdWords API Forum
Hi,

In my tests the keyword stats were returned in the same order that
they were passed in (using one RelatedToKeywordSearchParameter with
many keywords). Also, if you request the attribute KEYWORD you can
get back the keyword value again with your results.

Best,
- Eric Koleda, AdWords API Team

Reply all
Reply to author
Forward
0 new messages