【发布时间】:2019-01-23 10:41:11
【问题描述】:
我正在尝试通过 Google Ads API 获取放置在 Google Ads 中的所有广告时间表,并获取开始和结束时间(小时和分钟),以将其与一些现有值进行比较,并根据它们是否存在相应的不同进行更新。
这是我的代码,显示了我在哪里迭代返回的广告时间表。
foreach($campaigns as $camp) {
// Get restaurant and details
$res = RestaurantsService::getRestaurantByName($camp->getName());
$hours =$res->getHours()->dequeue();
$start = explode("-",$hours)[0];
$end = explode("-",$hours)[1];
// Get current ad schedules as they are now
$campaignAdSchedules = self::getCampaignAdSchedule($campaignCriterionService,$camp->getId());
if ($campaignAdSchedules == null){
$operations = [];
$schedule = new AdSchedule();
$schedule->setDayOfWeek(self::DAYS[date("N")-1]);
$schedule->setStartHour((int)substr($start,0,2));
$schedule->setStartMinute(MinuteOfHour::ZERO);
$schedule->setEndHour((int)substr($end,0,2));
$schedule->setEndMinute(MinuteOfHour::ZERO);
$operation = new CampaignCriterionOperation();
$criterion = new CampaignCriterion();
$criterion->setCampaignId($camp->getId());
$criterion->setCriterion($schedule);
$operation->setOperand($criterion);
$operation->setOperator(Operator::ADD);
$operations[] = $operation;
$campaignCriterionService->mutate($operations);
} else {
foreach($campaignAdSchedules as $adSchedule){
---> $schedule = $adSchedule->getCriterion(); <---
}
}
}
这里标有箭头的线是我遇到问题的线。 getCriterion() 函数返回一个 Criterion 对象,它没有 getStartHour() 等方法。我尝试过转换它,但没有找到正确的方法。
非常感谢您的帮助!
【问题讨论】:
标签: php ads google-api-php-client