Hi.

You can find this example in older releases of Adwords API PHP
Library.
Main idea why old version is not works, in v201109 were changed idea
of setting targeting.
Now you need to specify not country, language or other string codes,
but integer IDs of them.

Here is example which I've:

<?php
/**
 * This example gets keyword traffic estimates.
 *
 * Tags: TrafficEstimatorService.get
 * Restriction: adwords-only
 *
 * PHP version 5
 *
 * Copyright 2011, 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
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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    GoogleApiAdsAdWords
 * @subpackage v201109
 * @category   WebServices
 * @copyright  2011, Google Inc. All Rights Reserved.
 * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache
License,
 *             Version 2.0
 * @author     Eric Koleda <api.ekol...@gmail.com>
 */

error_reporting(E_STRICT | E_ALL);

// You can set the include path to src directory or reference
// AdWordsUser.php directly via require_once.
// $path = '/path/to/aw_api_php_lib/src';
$path = dirname(__FILE__) . '/../../src';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

require_once 'Google/Api/Ads/AdWords/Lib/AdWordsUser.php';

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

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

  // Get the TrafficEstimatorService.
  $trafficEstimatorService =
      $user->GetService('TrafficEstimatorService', 'v201109');

  // 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('cruise', '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;

  // Get traffic estimates.
  $result = $trafficEstimatorService->get($selector);

  // Display traffic estimates.
  if (isset($result)) {
    $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: %.0f\n", $meanAverageCpc);
        printf("  Estimated ad position: %.2f \n",
$meanAveragePosition);
        printf("  Estimated daily clicks: %d\n", $meanClicks);
        printf("  Estimated daily cost: %.0f\n\n", $meanTotalCost);
      }
    }
  } else {
    print "No traffic estimates were returned.\n";
  }
} catch (Exception $e) {
  print $e->getMessage();
}
?>

Regards,
Evgeniy.

On 1 фев, 03:17, Yakito <adwo...@vannana.com> wrote:
> Hello,
> I am new to the AdWords API and I am trying to understand how to use
> the different services. I am having problems with the
> TrafficEstimatorService as there is no example in the current version
> of the PHP API. When I try to use the previous version API I get some
> error with the class "CountryTarget()" that does not exists in the
> current version.
>
> This is the code I am testing:
>
> $path = dirname(__FILE__) . '/../../../src';
> set_include_path(get_include_path() . PATH_SEPARATOR . $path);
>
> require_once 'Google/Api/Ads/AdWords/Lib/AdWordsUser.php';
> require_once 'Google/Api/Ads/Common/Util/MapUtils.php';
>
> // Constants used in the example.
> define('PAGE_SIZE', 500);
> /**
>  * Runs the example.
>  * @param AdWordsUser $user the user to run the example with
>  */
> function GetKeywordIdeasExample(AdWordsUser $user) {
>   // Get the service, which loads the required classes.
>   $targetingIdeaService = $user->GetService('TrafficEstimatorService',
> 'v201109');
>   $keywords = array();
>   $keywords[] = new Keyword('mars cruise', 'BROAD');
>   $keywords[] = new Keyword('cheap cruise', 'PHRASE');
>   $keywords[] = new Keyword('cruise', 'EXACT');
>
>   // Create a keyword estimate request for each keyword.
>   $keywordEstimateRequests = array();
>   foreach ($keywords as $keyword) {
>     $keywordEstimateRequest = new KeywordEstimateRequest();
>     $keywordEstimateRequest->keyword = $keyword;
>     $keywordEstimateRequests[] = $keywordEstimateRequest;
>   }
>
>   // Create ad group estimate requests.
>   $adGroupEstimateRequest = new AdGroupEstimateRequest();
>   $adGroupEstimateRequest->keywordEstimateRequests =
> $keywordEstimateRequests;
>   $adGroupEstimateRequest->maxCpc = new Money(1000000);
>   $adGroupEstimateRequests = array($adGroupEstimateRequest);
>
>   // Create campaign estimate requests.
>   $campaignEstimateRequest = new CampaignEstimateRequest();
>   $campaignEstimateRequest->adGroupEstimateRequests =
> $adGroupEstimateRequests;
>   $campaignEstimateRequest->targets = array(new CountryTarget('US'),
>       new LanguageTarget('en'));
>   $campaignEstimateRequests = array($campaignEstimateRequest);
>
>   // Create selector.
>   $selector = new TrafficEstimatorSelector();
>   $selector->campaignEstimateRequests = $campaignEstimateRequests;
>
>   // Get traffic estimates.
>   $result = $trafficEstimatorService->get($selector);
>
>   // Display traffic estimates.
>   if (isset($result)) {
>     $keywordEstimates =
>         $result->campaignEstimates[0]->adGroupEstimates[0]->keywordEstimates;
>
>     for ($i = 0; $i < sizeof($keywordEstimates); $i++) {
>       $keyword = $keywordEstimateRequests[$i]->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->clicks
>           + $keywordEstimate->max->clicks) / 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: %.0f\n", $meanAverageCpc);
>       printf("  Estimated ad position: %.2f \n",
> $meanAveragePosition);
>       printf("  Estimated daily clicks: %d\n", $meanClicks);
>       printf("  Estimated daily cost: %.0f\n\n", $meanTotalCost);
>     }
>   } else {
>     print "No traffic estimates were returned.\n";
>   }
>
> }
>
> 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.
>   GetKeywordIdeasExample($user);} catch (Exception $e) {
>
>   printf("An error has occurred: %s\n", $e->getMessage());
>
> }
>
> The error is on line 72, but remember thats an example from a previous
> version of the API. Any tip in the right direction will be much
> appreciated!
>
> Thanks!

-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
http://adwordsapi.blogspot.com
http://groups.google.com/group/adwords-api
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

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

Reply via email to