[SelectorError.INVALID_PREDICATE_VALUE @ serviceSelector; errorDetails:]

874 views
Skip to first unread message

Peter Stannett

unread,
Apr 21, 2011, 6:02:38 AM4/21/11
to AdWords API Forum
HI all

I'm trying to run the GetAllAds.php example in version V201101 and I
get [SelectorError.INVALID_PREDICATE_VALUE @ serviceSelector;
errorDetails:] error

I have $adGroupId=(float) commented out as I want to retrieve all ads.

Can anyone help?

Thanks
Peter

Peter Stannett

unread,
Apr 21, 2011, 6:27:48 AM4/21/11
to adwor...@googlegroups.com
It's ok! Everyone sit back down! I realised I had to amend $adGroupIdPredicate to lose the array($adgroupId) and change the $selector->predicates=array($statusPredicate) and lose the $adGroupId variable.

At least, I think that's what I had to do. It's worked anyway!

Peter Stannett

unread,
Apr 21, 2011, 7:08:07 AM4/21/11
to adwor...@googlegroups.com
However I am trying to download all the ads into a csv and I am having difficulty implementing the report service. Could someone explain firstly how I get to print out all the ads onto the screen (at the moment I have just Ad with id xxxx etc showing, not the headline etc that I have chosen as my selector fields) and secondly how I implement the Add report definition. 

Many thanks
Peter

Peter Stannett

unread,
Apr 21, 2011, 10:28:02 AM4/21/11
to adwor...@googlegroups.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';
require_once 'Google/Api/Ads/AdWords/Util/ReportUtils.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 AdGroupAdService.
  $adGroupAdService = $user->GetAdGroupAdService('v201101');

//  $adGroupId = (float) '';

  // Create selector.
  $selector = new Selector();
  $selector->fields = array('CampaignName', 'AdGroupName', 'Headline', 'Description1', 'Description2');
  $selector->ordering = array(new OrderBy('Id', 'ASCENDING'));


  // Amended predicates.
  $adGroupIdPredicate = new Predicate('AdGroupId', 'IN');
  // By default disabled ads aren't returned by the selector. To return them
  // include the DISABLED status in a predicate.
  $statusPredicate =new Predicate('Status', 'IN', array('ENABLED'));
  
  //Amended Line
  $selector->predicates = array($statusPredicate);

  // Get all ads.
  $page = $adGroupAdService->get($selector);

  // Display ads.
  if (isset($page->entries)) {
    foreach ($page->entries as $adGroupAd) {
      printf("Ad with id '%s', type '%s', and status '%s' was found.\n<br>",
        $adGroupAd->ad->id, $adGroupAd->ad->AdType, $adGroupAd->status);
      
    }
  }
  
    // Create report definition.
  $reportDefinition = new ReportDefinition();
  $reportDefinition->reportName = 'AD performance report #' . time();
  $reportDefinition->reportType = 'AD_PERFORMANCE_REPORT';
  $reportDefinition->downloadFormat = 'CSV';
  $reportDefinition->selector = $selector;


  // Create operations.
  $operation = new ReportDefinitionOperation();
  $operation->operand = $reportDefinition;
  $operation->operator = 'ADD';

  $operations = array($operation);

  // Add report definition.
  $result = $reportDefinitionService->mutate($operations);

  // Display report definitions.
  if ($result != null) {
    foreach ($result as $reportDefinition) {
      printf("Report definition with name '%s' and id '%s' was added.\n",
       $reportDefinition->reportName, $reportDefinition->id);   

$reportDefinitionId = $reportDefinition->id;
   $fileName = 'tv_g_ppc_ad_data.csv';
$path = dirname(__FILE__) . '/data/' . $fileName;


 // Download report.
  ReportUtils::DownloadReport($reportDefinitionId, $path, $user);

  printf("Report with definition id '%s' was downloaded to '%s'.\n",
      $reportDefinitionId, $path, $fileName);*/
      }
    }
  
  
  else {
    print "No ads were found.\n";
  }
} catch (Exception $e) {
  print $e->getMessage();
}

Kevin Winter

unread,
Apr 27, 2011, 10:05:29 AM4/27/11
to adwor...@googlegroups.com
Hi Peter,
  In the foreach loop over $page->entries you should be able to do an instanceof to verify that the result is a TextAd and then pull out the headline like this: $adGroupAd->ad->headline

-Kevin Winter
AdWords API Team

Peter Stannett

unread,
Apr 28, 2011, 7:53:27 AM4/28/11
to Kevin....@google.com, adwor...@googlegroups.com
HI Kevin

Thanks for the info, though I'm not too sure what you mean?

I apologise but my php knowledge is quite limited at the moment! Could you elaborate further? I would appreciate it. 
Thanks
Peter
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwor...@googlegroups.com
To unsubscribe from this group, send email to
adwords-api...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en

Kevin Winter

unread,
Apr 28, 2011, 9:30:34 AM4/28/11
to adwor...@googlegroups.com, Kevin....@google.com
Hi Peter,
  The GetGeoLocationInfo code example demonstrates what I was talking about:


The code examples have lots of useful tips and tricks about using the API.  They are a great resource for someone new.

- Kevin Winter
AdWords API Team
Reply all
Reply to author
Forward
0 new messages