The new SEARCH_VOLUME is equivalent to GLOBAL_MONTHLY_SEARCHES when no LocationSearchParameter and LanguageSearchParameter are specified, on the flip side SEARCH_VOLUME is equivalent to AVERAGE_TARGETED_MONTHLY_SEARCHES if a language and/or a location is required.
Don't get me wrong I'm not being judgmental, I'm just the dev in the story, but if for some reason one day I decide to change the behaviour of my applications/code without notice I don't think the business will appreciate it...
How long will the 201109 version be supported? The code still works for the moment...
We recently published a blog post talking about these numbers: http://googleadsdeveloper.blogspot.com/2012/11/understanding-adwords-api.html
Amazing...
package uber.keyword.bussiness;
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import com.google.api.ads.adwords.axis.factory.AdWordsServices;
import com.google.api.ads.adwords.axis.v201406.cm.ApiException;
import com.google.api.ads.adwords.axis.v201406.cm.Language;
import com.google.api.ads.adwords.axis.v201406.cm.Location;
import com.google.api.ads.adwords.axis.v201406.cm.Money;
import com.google.api.ads.adwords.axis.v201406.cm.Paging;
import com.google.api.ads.adwords.axis.v201406.o.Attribute;
import com.google.api.ads.adwords.axis.v201406.o.AttributeType;
import com.google.api.ads.adwords.axis.v201406.o.IdeaType;
import com.google.api.ads.adwords.axis.v201406.o.LanguageSearchParameter;
import com.google.api.ads.adwords.axis.v201406.o.LocationSearchParameter;
import com.google.api.ads.adwords.axis.v201406.o.LongAttribute;
import com.google.api.ads.adwords.axis.v201406.o.MoneyAttribute;
import com.google.api.ads.adwords.axis.v201406.o.RelatedToQuerySearchParameter;
import com.google.api.ads.adwords.axis.v201406.o.RequestType;
import com.google.api.ads.adwords.axis.v201406.o.SearchParameter;
import com.google.api.ads.adwords.axis.v201406.o.StringAttribute;
import com.google.api.ads.adwords.axis.v201406.o.TargetingIdea;
import com.google.api.ads.adwords.axis.v201406.o.TargetingIdeaPage;
import com.google.api.ads.adwords.axis.v201406.o.TargetingIdeaSelector;
import com.google.api.ads.adwords.axis.v201406.o.TargetingIdeaServiceInterface;
import com.google.api.ads.adwords.axis.v201406.o.Type_AttributeMapEntry;
import com.google.api.ads.adwords.lib.client.AdWordsSession;
import com.google.api.ads.common.lib.auth.OfflineCredentials;
import com.google.api.ads.common.lib.auth.OfflineCredentials.Api;
import com.google.api.ads.common.lib.conf.ConfigurationLoadException;
import com.google.api.ads.common.lib.exception.OAuthException;
import com.google.api.ads.common.lib.exception.ValidationException;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.googleapis.auth.clientlogin.ClientLoginResponseException;
import java.sql.Connection;
import uber.connection.Dbcon;
import uber.keywordbeans.AdwordBean;
import uber.keywordbeans.GoogleAPIBean;
public class Calculate_CPC_MCC {
private static final String clientId =
private static final String clientSecret =
private static final String refreshToken =
private static final String developerToken =
private static final String userAgent =
public AdwordBean getCPC_MCC(String keyword) throws ClientLoginResponseException, IOException, ValidationException,
ConfigurationLoadException, OAuthException, ApiException, ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException
{
String[] keywords=new String[]{keyword};
String finalresult="";
String[] locationNames = new String[] { "Paris", "Quebec", "Spain", "Deutschland" };
String kwd=keyword;
Long monthlySearches=null;
String monthltSearches_string="--";
Money avgCpc=null;
int k_id=0;
String k="--";
AdwordBean ad=new AdwordBean();
Connection con=new Dbcon().getConnection();
try {
Credential oAuth2Credential = new OfflineCredentials.Builder()
.forApi(Api.ADWORDS)
.withClientSecrets(clientId, clientSecret)
.withRefreshToken(refreshToken)
.build()
.generateCredential();
AdWordsSession session = new AdWordsSession.Builder()
.withDeveloperToken(developerToken)
.withUserAgent(userAgent)
.withOAuth2Credential(oAuth2Credential)
.build();
AdWordsServices adWordsServices = new AdWordsServices();
TargetingIdeaServiceInterface targetingIdeaService = adWordsServices.get(session,TargetingIdeaServiceInterface.class);
TargetingIdeaSelector selector = new TargetingIdeaSelector();
selector.setRequestType(RequestType.STATS);
selector.setIdeaType(IdeaType.KEYWORD);
selector.setRequestedAttributeTypes(new AttributeType[] { AttributeType.KEYWORD_TEXT, AttributeType.SEARCH_VOLUME, AttributeType.AVERAGE_CPC });
Language language = new Language();
language.setId(1000L);
Location location = new Location();
location.setId(2356L);
RelatedToQuerySearchParameter relatedToQuerySearchParameter = new RelatedToQuerySearchParameter();
relatedToQuerySearchParameter.setQueries(keywords);
LocationSearchParameter locationSearchParameter = new LocationSearchParameter();
locationSearchParameter.setLocations(new Location[] { location });
LanguageSearchParameter languageSearchParameter = new LanguageSearchParameter();
languageSearchParameter.setLanguages(new Language[] { language });
selector.setSearchParameters(new SearchParameter[] { relatedToQuerySearchParameter, locationSearchParameter,
languageSearchParameter // if not provided locationSearchParameter, languageSearchParameter then result
// is global
});
selector.setLocaleCode("IN");
// System.out.println(selector.getLocaleCode());
Paging paging = new Paging();
paging.setStartIndex(0);
paging.setNumberResults(keywords.length);
selector.setPaging(paging);
TargetingIdeaPage page = targetingIdeaService.get(selector);
if (page.getEntries() != null && page.getEntries().length > 0) {
for (TargetingIdea targetingIdea : page.getEntries()) {
Map<AttributeType, Attribute> data = toMap(targetingIdea.getData());
kwd = ((StringAttribute) data.get(AttributeType.KEYWORD_TEXT)).getValue();
monthlySearches = ((LongAttribute) data.get(AttributeType.SEARCH_VOLUME)).getValue();
avgCpc = ((MoneyAttribute) data.get(AttributeType.AVERAGE_CPC)).getValue();
System.out.println(monthlySearches);
System.out.println( kwd);
if ((avgCpc==null)|| avgCpc.equals("")){
k="--";
//finalresult = kwd + "@@NULL@@" + monthlySearches;
// System.out.println(kwd + ", " + k + ", " + monthlySearches );
}
if((monthlySearches==null|| monthlySearches.equals(""))){
monthltSearches_string="--";
}
if(avgCpc!= null && monthlySearches!= null) {
monthltSearches_string=monthlySearches.toString();
k=String.format("%.1f",(avgCpc.getMicroAmount().floatValue()/1000000.0)) +"";
//finalresult = kwd + "@@" + avgCpc.getMicroAmount() / 1000000.0 + "@@" + monthlySearches ;
//System.out.println(kwd + ", " + avgCpc.getMicroAmount() / 1000000.0 + ", " + monthlySearches);
}
}
}
// CallableStatement cs1=con.prepareCall("{call sp_RetriveKwId(?,?)}");
// cs1.setString(1,kwd );
// cs1.registerOutParameter(2,java.sql.Types.INTEGER);
// cs1.executeUpdate();
// k_id=cs1.getInt(2);
//
//
// ad.setCpc(k);
// ad.setKw_id(k_id+"");
// ad.setKeyword(kwd);
// ad.setMCC(monthltSearches_string);
// ad.setFlag(true);
}
catch (Exception e){
e.printStackTrace();
}
return ad;
}
public static Map<AttributeType, Attribute> toMap(Type_AttributeMapEntry[] data) {
Map<AttributeType, Attribute> result = new HashMap<AttributeType, Attribute>();
for (Type_AttributeMapEntry entry: data) {
result.put(entry.getKey(), entry.getValue());
}
return result;
}
public static void main(String args[]) throws ApiException, ClientLoginResponseException, OAuthException, ClassNotFoundException, InstantiationException, IllegalAccessException, IOException, ValidationException, ConfigurationLoadException, SQLException
{
new Calculate_CPC_MCC().getCPC_MCC("Ballerina");
}
}
...