Hi I am using AdgroupAdservice method retrieve the 
cost,cpc,impression,ctr,conversion etc by using the following code.

Code:


require_once 
dirname(__FILE__).'/adwordsAPI/src/Google/Api/Ads/AdWords/Lib/AdWordsUser.php';
//require_once 
dirname(__FILE__).'/adwordsAPI/src/Google/Api/Ads/AdWords/v201406/AdGroupCriterionService.php';
require_once 
dirname(__FILE__).'/adwordsAPI/examples/AdWords/v201406/init.php';
//echo "values is :".$var;
$adGroupId = $var;
$retval=array();
function GetTextAdsExample(AdWordsUser $user, $adGroupId) {
// Get the service, which loads the required classes.
$adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION);

  // Create selector.
  $selector = new Selector();
  $selector->fields = array('Headline', 'Id','Description1', 
'Description2', 'DisplayUrl', 'Url', 'Status', 'AverageCpc', 
'AveragePosition', 'Clicks', 'Conversions', 'Cost','Ctr', 'Impressions');
  $selector->ordering[] = new OrderBy('Headline', 'ASCENDING');

  // Create predicates.
  $selector->predicates[] = new Predicate('AdGroupId', 'IN', 
array($adGroupId));
  $selector->predicates[] = new Predicate('AdType', 'IN', array('TEXT_AD'));
  // By default disabled ads aren't returned by the selector. To return them
  // include the DISABLED status in a predicate.
  $selector->predicates[] =
  new Predicate('Status', 'IN', array('ENABLED', 'PAUSED', 'DISABLED'));

  // Create paging controls.
  $selector->paging = new Paging(0, 
AdWordsConstants::RECOMMENDED_PAGE_SIZE);

  do {
// Make the get request.
$page = $adGroupAdService->get($selector);

// Display results.
if (isset($page->entries)) {
  foreach ($page->entries as $adGroupAd) {
  global $retval;
  $head=$adGroupAd->ad->headline;
  $adid=$adGroupAd->ad->id;
  $des1=$adGroupAd->ad->description1;
  $des2=$adGroupAd->ad->description2;
  $url=$adGroupAd->ad->displayUrl;
  $clicks=$adGroupAd->stats->clicks;
  $cpc=$adGroupAd->stats->averageCpc->microAmount / 1000000;
  $conversions=$adGroupAd->stats->conversions;
  $cost=$adGroupAd->stats->cost->microAmount / 1000000;
  $ctr=$adGroupAd->stats->ctr;
  $imp=$adGroupAd->stats->impressions;
  $ap=$adGroupAd->stats->averagePosition;
//printf("Text ad with headline '%s' and ID '%s' was found.\n",
//$adGroupAd->ad->headline, $adGroupAd->ad->id);
array_push($retval,array("hea"=>$head,"id"=>$adid ,"desc"=>$des1 
,"desc2"=>$des2,"url"=>$url,
"cli"=>$clicks,"cpc"=>$cpc,"con"=>$conversions,"cost"=>$cost,"ctr"=>$ctr,"imp"=>$imp,"ap"=>$ap
 ));
}
 echo json_encode($retval); 
} else {
  //print "No text ads were found.\n";
}

// Advance the paging index.
$selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
  } while ($page->totalNumEntries > $selector->paging->startIndex);
}


ERROR:


An error has occurred: [SelectorError.INVALID_FIELD_NAME @ serviceSelector; 
trigger:'AverageCpc', SelectorError.INVALID_FIELD_NAME @ serviceSelector; 
trigger:'AveragePosition', SelectorError.INVALID_FIELD_NAME @ serviceSelector; 
trigger:'Clicks', SelectorError.INVALID_FIELD_NAME @ serviceSelector; 
trigger:'Conversions', SelectorError.INVALID_FIELD_NAME @ serviceSelector; 
trigger:'Cost', SelectorError.INVALID_FIELD_NAME @ serviceSelector; 
trigger:'Ctr', SelectorError.INVALID_FIELD_NAME @ serviceSelector; 
trigger:'Impressions']

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
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/8ff9b8a8-2930-4650-84c0-25ba839bd530%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to