The error is happening at $page = $adGroupService->get($selector);

On Friday, June 29, 2018 at 12:45:39 PM UTC-6, sz...@mymail.mines.edu wrote:
>
> Hello, I am currently using the adgroup performance report to report on a 
> few metrics, and then pause certain ad groups that are above certain 
> thresholds. However, my selector is coming back as null. Here is my code:
>
> namespace Google\AdsApi\Examples\AdWords\v201806\Reporting;
>
> require __DIR__ . '/../../../../../vendor/autoload.php';
>
> use Google\AdsApi\AdWords\AdWordsSession;
> use Google\AdsApi\AdWords\AdWordsSessionBuilder;
> use Google\AdsApi\AdWords\Reporting\v201806\DownloadFormat;
> use Google\AdsApi\AdWords\Reporting\v201806\ReportDefinition;
> use Google\AdsApi\AdWords\Reporting\v201806\ReportDefinitionDateRangeType;
> use Google\AdsApi\AdWords\Reporting\v201806\ReportDownloader;
> use Google\AdsApi\AdWords\ReportSettingsBuilder;
> use Google\AdsApi\AdWords\v201806\cm\Predicate;
> use Google\AdsApi\AdWords\v201806\cm\PredicateOperator;
> use Google\AdsApi\AdWords\v201806\cm\ReportDefinitionReportType;
> use Google\AdsApi\AdWords\v201806\cm\Selector;
> use Google\AdsApi\Common\OAuth2TokenBuilder;
> use Google\AdsApi\AdWords\v201806\cm\Paging;
> use Google\AdsApi\AdWords\v201806\cm\AdGroup;
> use Google\AdsApi\AdWords\v201806\cm\AdGroupOperation;
> use Google\AdsApi\AdWords\v201806\cm\AdGroupService;
>
>
>
> /**
>  * Downloads CRITERIA_PERFORMANCE_REPORT for the specified client customer 
> ID.
>  */
> class DownloadCriteriaReportWithSelector
> {
>     const PAGE_LIMIT = 500;
>     public static function runExample(AdWordsSession $session, $filePath)
>     {
>         // Create selector.
>         $selector = new Selector(); 
>         $selector->setFields(
>             [
>                 'CampaignId',
>                 'AdGroupId',
>                 //'Id',
>                 'Cost',
>                 'Clicks',
>                 'AverageCpc',
>                 'AllConversionRate',
>                 'AllConversions',
>                 'CostPerConversion',
>                 'ValuePerConversion'
>                 
>                 // *Add or remove criteria to change what fields you want 
> the report to print out --Sean*
>             ]
>         );
>
>          //Use a predicate to filter out paused criteria (this is 
> optional).
>         $selector->setPredicates(
>             [
>                 new Predicate('AdGroupStatus', PredicateOperator::NOT_IN, 
> ['PAUSED']),
>                 //new Predicate('AverageCpc', 
> PredicateOperator::GREATER_THAN, array(0))
>                 
>                  //*Edit the number in the array just above to change the 
> threhold of the AverageCpc --Sean*
>             ]
>         );
>         
>         $selector->setPaging(new Paging(0, self::PAGE_LIMIT));
>         
>         $totalNumEntries = 0;
>         do {
>             // Retrieve ad groups one page at a time, continuing to 
> request pages
>             // until all ad groups have been retrieved.
>             $page = $adGroupService->get($selector);
>             
>             // Print out some information for each ad group.
>             if ($page->getEntries() !== null) {
>                 $totalNumEntries = $page->getTotalNumEntries();
>                 foreach ($page->getEntries() as $adGroup) {
>                    
>                     //setting up the pause operation
>                     $operations = [];
>                     $adGroup -> setStatus(AdGroupStatus.PAUSED);
>                     $operation = new AdGroupOperation();
>                     $operation->setOperand($adGroup);
>                     $operation->setOperator(Operator::SET);
>                     $operations[] = $operation;
>                     // Update the ad group on the server.
>                     $result = $adGroupService->mutate($operations);
>                     $adGroup->setStatus(AdGroupStatus::PAUSED);
>
>                     $adGroup = $result->getValue()[0];
>                     
>                     
>                     printf(
>                         "Ad group with name %d and status '%s' was 
> found.\n",
>                         $adGroup->getName(),
>                         $adGroup->getStatus()
>                          
>                     );
>                  
>                 
>                 }
>             }
>
>             $selector->getPaging()->setStartIndex(
>                 $selector->getPaging()->getStartIndex() + self::PAGE_LIMIT
>             );
>         } while ($selector->getPaging()->getStartIndex() < 
> $totalNumEntries);
>
>         // Create report definition.
>         $reportDefinition = new ReportDefinition();
>         $reportDefinition->setSelector($selector);
>         $reportDefinition->setReportName(
>             date("m-d-Y") . '  Ad Performance Report for Powder7 ' 
>         );
>         $reportDefinition->setDateRangeType(
>             ReportDefinitionDateRangeType::LAST_7_DAYS
>             
>             // Edit the line above to change the date range you wish the 
> report to look for --Sean*
>         );
>         $reportDefinition->setReportType(
>             ReportDefinitionReportType::ADGROUP_PERFORMANCE_REPORT
>         );
>         $reportDefinition->setDownloadFormat(DownloadFormat::CSV);
>
>         // Download report.
>         $reportDownloader = new ReportDownloader($session);
>         // Optional: If you need to adjust report settings just for this 
> one
>         // request, you can create and supply the settings override here. 
> Otherwise,
>         // default values from the configuration file (adsapi_php.ini) are 
> used.
>         $reportSettingsOverride = (new 
> ReportSettingsBuilder())->includeZeroImpressions(true)->build();
>         $reportDownloadResult = $reportDownloader->downloadReport(
>             $reportDefinition,
>             $reportSettingsOverride
>             
>         );
>         $reportDownloadResult->saveToFile($filePath);
>         
>         printf(
>             "Report with name '%s' was downloaded to '%s'.\n",
>             $reportDefinition->getReportName(),
>             $filePath
>         );
>     }
>
>     public static function main()
>     {
>         // Generate a refreshable OAuth2 credential for authentication.
>         $oAuth2Credential = (new 
> OAuth2TokenBuilder())->fromFile()->build();
>
>         // See: AdWordsSessionBuilder for setting a client customer ID 
> that is
>         // different from that specified in your adsapi_php.ini file.
>         // Construct an API session configured from a properties file and 
> the
>         // OAuth2 credentials above.
>         $session = (new 
> AdWordsSessionBuilder())->fromFile()->withOAuth2Credential($oAuth2Credential)->build();
>             
>         $filePath = sprintf(
>             '%s.csv',
>             tempnam(sys_get_temp_dir(), 'Ad-Performance-Report-')
>         );
>         self::runExample($session, $filePath);
>     }
> }
>
> DownloadCriteriaReportWithSelector::main();
>
> I've been looking around and cant figure out why the selector is null. Any 
> help would be appreciated.
>
> Thanks,
>
> Sean
>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads 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 and Google Ads 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 https://groups.google.com/group/adwords-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/a14c481a-e9f2-4aab-9344-c201d35fd615%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to