/** * Adds a new ad unit to a publisher ad client. * * @param $service Google_Service_AdSenseHost AdSenseHost service object on * which to run the requests. * @param $accountId string the ID for the publisher account to be used. * @param $adClientId string the ID for the ad client to be used. * @return Google_Service_AdSenseHost_AdUnit the created ad unit. */ public static function run($service, $accountId, $adClientId) { $separator = str_repeat('=', 80) . "\n"; print $separator; printf("Adding ad unit to ad client %s\n", $adClientId); print $separator; $adUnit = new Google_Service_AdSenseHost_AdUnit(); $adUnit->setName('Ad Unit #' . getUniqueName()); $contentAdsSettings = new Google_Service_AdSenseHost_AdUnitContentAdsSettings(); $backupOption = new Google_Service_AdSenseHost_AdUnitContentAdsSettingsBackupOption(); $backupOption->setType('COLOR'); $backupOption->setColor('ffffff'); $contentAdsSettings->setBackupOption($backupOption); $contentAdsSettings->setSize('SIZE_200_200'); $contentAdsSettings->setType('TEXT'); $adUnit->setContentAdsSettings($contentAdsSettings); $customStyle = new Google_Service_AdSenseHost_AdStyle(); $colors = new Google_Service_AdSenseHost_AdStyleColors(); $colors->setBackground('ffffff'); $colors->setBorder('000000'); $colors->setText('000000'); $colors->setTitle('000000'); $colors->setUrl('0000ff'); $customStyle->setColors($colors); $customStyle->setCorners('SQUARE'); $font = new Google_Service_AdSenseHost_AdStyleFont(); $font->setFamily('ACCOUNT_DEFAULT_FAMILY'); $font->setSize('ACCOUNT_DEFAULT_SIZE'); $customStyle->setFont($font); $adUnit->setCustomStyle($customStyle); $result = $service->accounts_adunits->insert($accountId, $adClientId, $adUnit); printf("Ad unit with ID \"%s\", type \"%s\", name \"%s\" and status \"%s\" " . "was created.\n", $result->getId(), $result->getContentAdsSettings()->getType(), $result->getName(), $result->getStatus()); print "\n"; return $result; }
/** * Updates an ad unit on a publisher ad client. * * @param $service Google_Service_AdSenseHost AdSenseHost service object on * which to run the requests. * @param $accountId string the ID for the publisher account to be used. * @param $adClientId string the ID for the ad client to be used. * @param $adUnitId string the ID of the ad unit to be updated. * @return Google_Service_AdSenseHost_AdUnit the updated ad unit. */ public static function run($service, $accountId, $adClientId, $adUnitId) { $separator = str_repeat('=', 80) . "\n"; print $separator; printf("Updating ad unit %s\n", $adUnitId); print $separator; $adUnit = new Google_Service_AdSenseHost_AdUnit(); $contentAdsSettings = new Google_Service_AdSenseHost_AdUnitContentAdsSettings(); $customStyle = new Google_Service_AdSenseHost_AdStyle(); $colors = new Google_Service_AdSenseHost_AdStyleColors(); $colors->setText('ff0000'); $customStyle->setColors($colors); $adUnit->setCustomStyle($customStyle); $result = $service->accounts_adunits->patch($accountId, $adClientId, $adUnitId, $adUnit); printf("Ad unit with ID \"%s\" was updated with text color \"%s\"\n", $result->getId(), $result->getCustomStyle()->getColors()->getText()); print "\n"; return $result; }