I am using this code estimate the keyword traffic but it's always giving 
zero for cpc,daily clicks,daily cost and it's working fine ad position


please let me know the procedure to get these values that I have mentioned .


This is my code :


require_once dirname(dirname(__FILE__)) . '/init.php';

/**
 * Runs the example.
 * @param AdWordsUser $user the user to run the example with
 */
function EstimateKeywordTrafficExample(AdWordsUser $user) {
  // Get the service, which loads the required classes.
  $trafficEstimatorService =
      $user->GetService('TrafficEstimatorService', ADWORDS_VERSION);

  // Create keywords. Up to 2000 keywords can be passed in a single request.
  $keywords = array();
  $keywords[] = new Keyword('mars cruise', 'BROAD');
  $keywords[] = new Keyword('cheap cruise', 'PHRASE');
  $keywords[] = new Keyword('kidney stones treatment', 'EXACT');

  // Negative keywords don't return estimates, but adjust the estimates of 
the
  // other keywords in the hypothetical ad group.
  $negativeKeywords = array();
  $negativeKeywords[] = new Keyword('moon walk', 'BROAD');

  // Create a keyword estimate request for each keyword.
  $keywordEstimateRequests = array();
  foreach ($keywords as $keyword) {
    $keywordEstimateRequest = new KeywordEstimateRequest();
    $keywordEstimateRequest->keyword = $keyword;
    $keywordEstimateRequests[] = $keywordEstimateRequest;
  }

  // Create a keyword estimate request for each negative keyword.
  foreach ($negativeKeywords as $negativeKeyword) {
    $keywordEstimateRequest = new KeywordEstimateRequest();
    $keywordEstimateRequest->keyword = $negativeKeyword;
    $keywordEstimateRequest->isNegative = TRUE;
    $keywordEstimateRequests[] = $keywordEstimateRequest;
  }

  // Create ad group estimate requests.
  $adGroupEstimateRequest = new AdGroupEstimateRequest();
  $adGroupEstimateRequest->keywordEstimateRequests = 
$keywordEstimateRequests;
  $adGroupEstimateRequest->maxCpc = new Money(1000000);

  // Create campaign estimate requests.
  $campaignEstimateRequest = new CampaignEstimateRequest();
  $campaignEstimateRequest->adGroupEstimateRequests[] = 
$adGroupEstimateRequest;

  // Set targeting criteria. Only locations and languages are supported.
  $unitedStates = new Location();
  $unitedStates->id = 2840;
  $campaignEstimateRequest->criteria[] = $unitedStates;

  $english = new Language();
  $english->id = 1000;
  $campaignEstimateRequest->criteria[] = $english;

  // Create selector.
  $selector = new TrafficEstimatorSelector();
  $selector->campaignEstimateRequests[] = $campaignEstimateRequest;

  // Make the get request.
  $result = $trafficEstimatorService->get($selector);

  // Display results.
  $keywordEstimates =
      $result->campaignEstimates[0]->adGroupEstimates[0]->keywordEstimates;
  for ($i = 0; $i < sizeof($keywordEstimates); $i++) {
    $keywordEstimateRequest = $keywordEstimateRequests[$i];
    // Skip negative keywords, since they don't return estimates.
    if (!$keywordEstimateRequest->isNegative) {
      $keyword = $keywordEstimateRequest->keyword;
      $keywordEstimate = $keywordEstimates[$i];

      // Find the mean of the min and max values.
      $meanAverageCpc = ($keywordEstimate->min->averageCpc->microAmount
          + $keywordEstimate->max->averageCpc->microAmount) / 2;
      $meanAveragePosition = ($keywordEstimate->min->averagePosition
          + $keywordEstimate->max->averagePosition) / 2;
      $meanClicks = ($keywordEstimate->min->clicksPerDay
          + $keywordEstimate->max->clicksPerDay) / 2;
      $meanTotalCost = ($keywordEstimate->min->totalCost->microAmount
          + $keywordEstimate->max->totalCost->microAmount) / 2;

      printf("Results for the keyword with text '%s' and match type 
'%s':\n",
          $keyword->text, $keyword->matchType);
      printf("  Estimated average CPC in micros: %.0f\n", $meanAverageCpc);
      printf("  Estimated ad position: %.2f \n", $meanAveragePosition);
      printf("  Estimated daily clicks: %d\n", $meanClicks);
      printf("  Estimated daily cost in micros: %.0f\n\n", $meanTotalCost);
    }
  }
}

// Don't run the example if the file is being included.
if (__FILE__ != realpath($_SERVER['PHP_SELF'])) {
  return;
}

try {
  // Get AdWordsUser from credentials in "../auth.ini"
  // relative to the AdWordsUser.php file's directory.
  $user = new AdWordsUser();

  // Log every SOAP XML request and response.
  $user->LogAll();

  // Run the example.
  EstimateKeywordTrafficExample($user);
} catch (Exception $e) {
  printf("An error has occurred: %s\n", $e->getMessage());
}


-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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/21e6baf5-188b-4f09-bda6-40257c276da1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to