issue in retrieving existing AdSchedules from one's account

13 views
Skip to first unread message

Harisankar Mohanty

unread,
Jun 12, 2020, 3:06:16 PM6/12/20
to AdWords API and Google Ads API Forum
Hello Guys,


We are doing time of day bid adjustment using php adwords For that we need need to remove the existing AdSchedule first, then add the new ones. This is our code that we use to retrive the existing AdSchedules in our adwords acoount. But unfortunately we are not getting any result (0 result). Please suggest.

$campaignCriterionService = $adWordsServices->get($session, CampaignCriterionService::class);

        // Create a selector to select all campaign criteria for the specified
        // campaign.
        $selector = new Selector();
        $selector->setFields(['Id', 'CriteriaType', 'CampaignCriterionStatus']);
        $selector->setPredicates(
            [
                new Predicate('CampaignId', PredicateOperator::IN, [$campaignId]),
                new Predicate(
                    'CriteriaType',
                    PredicateOperator::IN,
                    [
                        'AD_SCHEDULE'
                    ]
                )
            ]
        );
        $selector->setPaging(new Paging(0, self::PAGE_LIMIT));

        $totalNumEntries = 0;
        $resultCampaignCriterion = [];
        do {
            // Retrieve campaign criteria one page at a time, continuing to request
            // pages until all campaign criteria have been retrieved.
            $page = $campaignCriterionService->get($selector);
            // Print out some information for each campaign criterion.
            if ($page->getEntries() !== null) {
                $totalNumEntries = $page->getTotalNumEntries();
                foreach ($page->getEntries() as $campaignCriterion) {
                    printf(
                        "Campaign targeting criterion with ID %d and type '%s' was found.\n",
                        $campaignCriterion->getCriterion()->getId(),
                        $campaignCriterion->getCriterion()->getType()
                    );
                }
            }

            $selector->getPaging()->setStartIndex(
                $selector->getPaging()->getStartIndex() + self::PAGE_LIMIT
            );
        } while ($selector->getPaging()->getStartIndex() < $totalNumEntries);
       
        //return $resultCampaignCriterion;
        printf("Number of results found: %d\n", $totalNumEntries);

Thank you in advance for your cooperation.

Google Ads API Forum Advisor Prod

unread,
Jun 12, 2020, 3:58:35 PM6/12/20
to harish....@gmail.com, adwor...@googlegroups.com
Hi Harisankar,

Please check whether you are running the API call from an MCC account and/or the campaign you are selecting has ad schedules in the UI.

If you aren't, please share your SOAP logs with me via reply privately to author so I can take a closer look.

Regards,
Anthony
Google Ads API Team

ref:_00D1U1174p._5004Q20YVY9:ref
Reply all
Reply to author
Forward
0 new messages