Getting Null response for some keywords requests

449 views
Skip to first unread message

Jorge Brasil

unread,
Dec 2, 2014, 10:53:11 AM12/2/14
to adwor...@googlegroups.com
Hi,

I am developing an application that uses the traffic estimation service to get some predictions for the keywords traffic for my company adds.

The issue is that for some keywords that are in one of our campaigns I get a null response from the API, also if I make multiple calls for the same keyword ate some point the response is going to be null.


here is my code


// Copyright 2014 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package adwords.axis.v201409.optimization;

import com.google.api.ads.adwords.axis.factory.AdWordsServices;
import com.google.api.ads.adwords.axis.v201409.cm.Criterion;
import com.google.api.ads.adwords.axis.v201409.cm.Keyword;
import com.google.api.ads.adwords.axis.v201409.cm.KeywordMatchType;
import com.google.api.ads.adwords.axis.v201409.cm.Language;
import com.google.api.ads.adwords.axis.v201409.cm.Location;
import com.google.api.ads.adwords.axis.v201409.cm.Money;
import com.google.api.ads.adwords.axis.v201409.o.AdGroupEstimateRequest;
import com.google.api.ads.adwords.axis.v201409.o.CampaignEstimateRequest;
import com.google.api.ads.adwords.axis.v201409.o.KeywordEstimate;
import com.google.api.ads.adwords.axis.v201409.o.KeywordEstimateRequest;
import com.google.api.ads.adwords.axis.v201409.o.TrafficEstimatorResult;
import com.google.api.ads.adwords.axis.v201409.o.TrafficEstimatorSelector;
import com.google.api.ads.adwords.axis.v201409.o.TrafficEstimatorServiceInterface;
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.client.auth.oauth2.Credential;

import java.util.ArrayList;
import java.util.List;

/**
 * This example gets keyword traffic estimates.
 *
 * Credentials and properties in {@code fromFile()} are pulled from the
 * "ads.properties" file. See README for more info.
 *
 * Tags: TrafficEstimatorService.get
 *
 * Category: adx-exclude
 *
 * @author Kevin Winter
 */
public class EstimateKeywordTraffic {
public static ArrayList parameters = new ArrayList();
public static ArrayList words_param = new ArrayList();
public static ArrayList bid_values = new ArrayList();
public static ArrayList copy_bid = new ArrayList();
private static  List<Money> bids = new ArrayList<Money>();
  
/*
public static void main(String[] args) throws Exception {
    // Generate a refreshable OAuth2 credential similar to a ClientLogin token
    // and can be used in place of a service account.
    Credential oAuth2Credential = new OfflineCredentials.Builder()
        .forApi(Api.ADWORDS)
        .fromFile()
        .build()
        .generateCredential();

    // Construct an AdWordsSession.
    AdWordsSession session = new AdWordsSession.Builder()
        .fromFile()
        .withOAuth2Credential(oAuth2Credential)
        .build();

    AdWordsServices adWordsServices = new AdWordsServices();

    runExample(adWordsServices, session);
  }
*/
  public static void runExample(
   
AdWordsServices adWordsServices, AdWordsSession session) throws Exception {
    // Get the TrafficEstimatorService.
 
 
 TrafficEstimatorServiceInterface trafficEstimatorService =
        adWordsServices.get(session, TrafficEstimatorServiceInterface.class);

    // Create keywords. Refer to the TrafficEstimatorService documentation for the maximum
    // number of keywords that can be passed in a single request.
    List<Keyword> keywords = new ArrayList<Keyword>();
  
    keywords.add(new Keyword(null, null, null, "public liability insurance", KeywordMatchType.PHRASE));
   //keywords.add(new Keyword(null, null, null, "Insurance public", KeywordMatchType.EXACT));
   //keywords.add(new Keyword(null, null, null, "insurance liability", KeywordMatchType.EXACT));
   keywords.add(new Keyword(null, null, null, "liability insurance", KeywordMatchType.BROAD));

    int number_of_keywords = keywords.size();
    
    bids.clear();
    bid_values.clear();
    words_param.clear();
    parameters.clear();
    bid_values =  utilities.Bids(number_of_keywords);
   
    for(int i = 0 ; i <bid_values.size(); i++ )
    {
     
     Double aux = (Double)bid_values.get(i)*100000;
     bids.add(new Money(null, aux.longValue()));
    }
    
    
    // Create a keyword estimate request for each keyword.
    List<KeywordEstimateRequest> keywordEstimateRequests = new ArrayList<KeywordEstimateRequest>();
    
    for (int i = 0 ; i < keywords.size() ; i++) {
        KeywordEstimateRequest keywordEstimateRequest = new KeywordEstimateRequest();
        keywordEstimateRequest.setKeyword(keywords.get(i)); 
        keywordEstimateRequest.setMaxCpc((bids.get(i)));
        keywordEstimateRequests.add(keywordEstimateRequest);  
    }
    
    // Create ad group estimate requests.
    List<AdGroupEstimateRequest> adGroupEstimateRequests = new ArrayList<AdGroupEstimateRequest>();
    AdGroupEstimateRequest adGroupEstimateRequest = new AdGroupEstimateRequest();
    adGroupEstimateRequest.setKeywordEstimateRequests(keywordEstimateRequests
        .toArray(new KeywordEstimateRequest[] {}));
  // adGroupEstimateRequest.setAdGroupId(505759692L);
    
    adGroupEstimateRequests.add(adGroupEstimateRequest);

    // Create campaign estimate requests.
    List<CampaignEstimateRequest> campaignEstimateRequests =
        new ArrayList<CampaignEstimateRequest>();
    CampaignEstimateRequest campaignEstimateRequest = new CampaignEstimateRequest();
    campaignEstimateRequest.setAdGroupEstimateRequests(adGroupEstimateRequests
        .toArray(new AdGroupEstimateRequest[] {}));
    Location unitedStates = new Location();
    unitedStates.setId(2826L);
    Language english = new Language();
    english.setId(1000L);
    campaignEstimateRequest.setCampaignId(18129492L);
    campaignEstimateRequest.setCriteria(new Criterion[] {unitedStates, english});
    campaignEstimateRequests.add(campaignEstimateRequest);

    // Create selector.
    TrafficEstimatorSelector selector = new TrafficEstimatorSelector();
    selector.setCampaignEstimateRequests(campaignEstimateRequests
        .toArray(new CampaignEstimateRequest[] {}));

    // Get traffic estimates.
    TrafficEstimatorResult result = trafficEstimatorService.get(selector);
    

    for(int i = 0 ; i < keywords.size();i ++)
    {
   
    Keyword keyword = keywordEstimateRequests.get(i).getKeyword();
   
    double minCPC = result.getCampaignEstimates()[0].getAdGroupEstimates()[0].getKeywordEstimates()[i].getMin().getAverageCpc().getMicroAmount();
    double maxCPC = result.getCampaignEstimates()[0].getAdGroupEstimates()[0].getKeywordEstimates()[i].getMax().getAverageCpc().getMicroAmount();
   
    double meanCpc = (minCPC + maxCPC) / 2.0 ;
   
    double minAveragePosition = result.getCampaignEstimates()[0].getAdGroupEstimates()[0].getKeywordEstimates()[i].getMin().getAveragePosition();
    double maxAveragePosition = result.getCampaignEstimates()[0].getAdGroupEstimates()[0].getKeywordEstimates()[i].getMax().getAveragePosition();
   
    double meanAveragePosition  =  (minAveragePosition + maxAveragePosition) / 2.0;
   
    double minClicks = result.getCampaignEstimates()[0].getAdGroupEstimates()[0].getKeywordEstimates()[i].getMin().getClicksPerDay();
    double maxClicks = result.getCampaignEstimates()[0].getAdGroupEstimates()[0].getKeywordEstimates()[i].getMax().getClicksPerDay();
   
    double meanClicks = (minClicks + maxClicks) / 2.0 ;
   
    double minImpressions = result.getCampaignEstimates()[0].getAdGroupEstimates()[0].getKeywordEstimates()[i].getMin().getImpressionsPerDay();
    double maxImpressions = result.getCampaignEstimates()[0].getAdGroupEstimates()[0].getKeywordEstimates()[i].getMax().getImpressionsPerDay();
   
    double meanImpressions = (minImpressions + maxImpressions) / 2.0 ;

 //   System.out.printf("Results for the keyword with text \'%s\':%n",keyword.getText());
 //   System.out.printf("\tEstimated average CPC: %.2f\n", meanCpc/1000000);
 //     System.out.printf("\tEstimated ad position: %.2f\n", meanAveragePosition);
 //       System.out.printf("\tEstimated daily clicks: %.2f\n", meanClicks);
 //       System.out.printf("\tEstimated daily Impressions: %.2f\n\n", meanImpressions);
  
   
        String [] features  = new String[5];
        String [] param = new String[2];
        param[0] = utilities.groupCPC(utilities.truncate(meanCpc/1000000,2));
        param[1] = utilities.groupPosition(utilities.truncate(meanAveragePosition,2));
        parameters.add(param);

        features[0] = keyword.getText();
        features[1] = Double.toString(meanCpc /1000000);
        features[2] = Double.toString(meanAveragePosition);
        features[3] = Double.toString(meanClicks);
        features[4] = Double.toString(meanImpressions);
        words_param.add(features);
       
  
}
  }
  }

I find it strange that the script works for some keywords but don't for others. Can you help me with this matter?

Best 

Jorge 

Josh Radcliff (AdWords API Team)

unread,
Dec 2, 2014, 1:24:35 PM12/2/14
to adwor...@googlegroups.com
Hi Jorge,

From your other post I thought you had resolved this issue. Also, when you say you get a "null response", do you mean you get a SOAP fault back?

Thanks,
Josh, AdWords API Team

Jorge Brasil

unread,
Dec 3, 2014, 6:07:18 AM12/3/14
to adwor...@googlegroups.com
Hi Josh,

My issue is that some parameters of the keywords estimations are coming as null. So I make the request with success but some in some responses a few parameters are null, for example cpc max = nulll  cpc min = null.
If I try the same keyword with the same value in python for example instead of null I get zero.
I can build exception on my script but do you have any idea why this is happening?

Best 

Josh Radcliff (AdWords API Team)

unread,
Dec 3, 2014, 9:13:29 AM12/3/14
to adwor...@googlegroups.com
Hi Jorge,

The keywords that are returning null for those values probably do not have enough search volume for AdWords to produce meaningful statistics. Starting in v201406 (see the release notes):

Changes to displayed values
  • TrafficEstimatorService will no longer return a 0 for a derived field if its denominator is zero; it will omit the field entirely.
Therefore, your code should handle nulls gracefully. I'll make a note of this so we update our code example accordingly.

Cheers,
Josh, AdWords API Team
Reply all
Reply to author
Forward
0 new messages