public function dfp() { App::import("Vendor", "DFPUser", array("file" => "Google/Api/Ads/Dfp/Lib/DfpUser.php")); $path = dirname(__FILE__) . '/../../..'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the CreativeService. $creativeService = $user->GetCreativeService('v201104'); // Set the ID of the advertiser (company) that all creatives will be // assigned to. $advertiserId = (double) '1917'; // Create an array to store local image creative objects. $imageCreatives = array(); for ($i = 0; $i < 5; $i++) { $imageCreative = new ImageCreative(); $imageCreative->name = 'Image creative #' . $i; $imageCreative->advertiserId = $advertiserId; $imageCreative->destinationUrl = 'http://google.com'; $imageCreative->imageName = 'image.jpg'; $imageCreative->imageByteArray = MediaUtils::GetBase64Data('http://www.google.com/intl/en/adwords/' . 'select/images/samples/inline.jpg'); $imageCreative->size = new Size(300, 250); $imageCreatives[] = $imageCreative; } // Create the image creatives on the server. $imageCreatives = $creativeService->createCreatives($imageCreatives); // Display results. if (isset($imageCreatives)) { foreach ($imageCreatives as $creative) { // Use instanceof to determine what type of creative was returned. if ($creative instanceof ImageCreative) { print 'An image creative with ID "' . $creative->id . '", name "' . $creative->name . '", and size {' . $creative->size->width . ', ' . $creative->size->height . "} was created and\n" . ' can be previewed at: ' . $creative->previewUrl . "\n"; } else { print 'A creative with ID "' . $creative->id . '", name "' . $creative->name . '", and type "' . $creative->CreativeType . "\" was created.\n"; } } } else { print "No creatives created.\n"; } } catch (Exception $e) { print $e->getMessage() . "\n"; } }
error_reporting(E_STRICT | E_ALL); // You can set the include path to src directory or reference // DfpUser.php directly via require_once. // $path = '/path/to/dfp_api_php_lib/src'; $path = dirname(__FILE__) . '/../../../src'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php'; require_once 'Google/Api/Ads/Common/Util/MapUtils.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the CreativeService. $creativeService = $user->GetCreativeService('v201103'); // Create bind variables. $vars = MapUtils::GetMapEntries(array('creativeType' => new TextValue('ImageCreative'))); // Create a statement to only select image creatives. $filterStatement = new Statement("WHERE creativeType = :creativeType LIMIT 500", $vars); // Get creatives by statement. $page = $creativeService->getCreativesByStatement($filterStatement); // Display results. if (isset($page->results)) { $i = $page->startIndex; foreach ($page->results as $creative) { print $i . ') Creative with ID "' . $creative->id . '", name "' . $creative->name . '", and type "' . $creative->CreativeType . "\" was found.\n"; $i++; } } print 'Number of results found: ' . $page->totalResultSetSize . "\n";
public function getCreative($id) { $token = "creative_" . $id; if (($c = Cache::read($token, "1day")) === false) { $path = dirname(__FILE__) . '/dfp/src'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the CreativeService. $creativeService = $user->GetCreativeService('v201108'); // Set the ID of the creative to get. $creativeId = (double) $id; // Get the creative. $creative = $creativeService->getCreative($creativeId); // Display results. if (isset($creative)) { $c = get_object_vars($creative); foreach ($c as $k => $v) { if (is_object($c[$k])) { $c[$k] = get_object_vars($c[$k]); } } Cache::write($token, $c, "1day"); } else { } } catch (Exception $e) { return $e->getMessage(); } } return $c; }