I just came Accross this issue, initialy i taught every thing was working 
fine because the UI and API wer Giving same data, bt as the number of 
keywords kept on increasing i saw difference of about 100 times in the 
search volume of 30% of the keywords i used. 



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");
    }
}



I hav used the location and the language setings and it gives the output 
for balerina as "Ballerina" for Location India Language English it shows 
33100, where as in the UI the it shows 1,900. Y is there such a vast 
differnce?? it is the same case for many keywords, like Boots . Plz Chck 
this. @kevin

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/adwords-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/86bdf002-7b5e-4efa-b021-f9c303f0f4a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to