本文整理汇总了PHP中MediaUtils类的典型用法代码示例。如果您正苦于以下问题:PHP MediaUtils类的具体用法?PHP MediaUtils怎么用?PHP MediaUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MediaUtils类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createNativeAdsCreative
public function createNativeAdsCreative($creativeAds = array())
{
// Set the ID of the advertiser (company) that all creatives will be
// assigned to.
$advertiserId = '44753810';
//[infeed]bukalapak
// Get the CreativeService.
$creativeService = $user->GetService('CreativeService', 'v201508');
// Use the image banner with optional third party tracking template.
$creativeTemplateId = 10052210;
//NativeAds - AllSite NEW FIXED
// Create the local custom creative object.
$templateCreative = new TemplateCreative();
$templateCreative->name = '[INFEED] Bukalapak - TESTING DFP API DUMMY CREATIVE II';
$templateCreative->advertiserId = $advertiserId;
$templateCreative->creativeTemplateId = $creativeTemplateId;
// Set the creative size.
$templateCreative->size = new Size(1, 1, false);
// Create the asset variable value.
$assetVariableValue = new AssetCreativeTemplateVariableValue();
$assetVariableValue->uniqueName = 'dfp_assetImg';
$assetVariableValue->assetByteArray = MediaUtils::GetBase64Data('http://s7.postimg.org/7yrycpxrr/justru.jpg');
// Filenames must be unique.
$assetVariableValue->fileName = sprintf('image%s.jpg', uniqid());
$templateCreative->creativeTemplateVariableValues[] = $assetVariableValue;
// Create the URL variable value.
$urlVariableValue = new UrlCreativeTemplateVariableValue();
$urlVariableValue->uniqueName = 'dfp_targetUrl';
$urlVariableValue->value = 'www.google.com';
$templateCreative->creativeTemplateVariableValues[] = $urlVariableValue;
// Create the target window variable value.
$targetWindowVariableValue = new StringCreativeTemplateVariableValue();
$targetWindowVariableValue->uniqueName = 'dfp_textArticle';
$targetWindowVariableValue->value = 'Jangan dihiraukan ini testing saja';
$templateCreative->creativeTemplateVariableValues[] = $targetWindowVariableValue;
// Create the template creative on the server.
$templateCreatives = $creativeService->createCreatives(array($templateCreative));
$result = array();
foreach ($templateCreatives as $templateCreative) {
$result['creative_id'] = $templateCreative->id;
$result['creative_name'] = $templateCreative->name;
$result['creative_type'] = get_class($templateCreative);
$result['creative_preview'] = $templateCreative->previewUrl;
}
}
示例2: AddHtml5Ad
/**
* Runs the example.
* @param AdWordsUser $user the user to run the example with
* @param string $adGroupId the ID of the ad group to add the ad to
*/
function AddHtml5Ad(AdWordsUser $user, $adGroupId)
{
// Get the AdGroupAdService, which loads the required classes.
$adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION);
// Create the template ad.
$html5Ad = new TemplateAd();
$html5Ad->name = 'Ad for HTML5';
$html5Ad->templateId = 419;
$html5Ad->finalUrls = array('http://example.com/html5');
$html5Ad->displayUrl = 'example.com/html5';
$dimensions = new Dimensions();
$dimensions->width = 300;
$dimensions->height = 250;
$html5Ad->dimensions = $dimensions;
// The HTML5 zip file contains all the HTML, CSS, and images needed for the
// HTML5 ad. For help on creating an HTML5 zip file, check out Google Web
// Designer (https://www.google.com/webdesigner/).
$html5Zip = MediaUtils::GetBase64Data('https://goo.gl/9Y7qI2');
// Create a media bundle containing the zip file with all the HTML5
// components.
// NOTE: You may also upload an HTML5 zip using MediaService.upload()
// and simply set the mediaId field below. See UploadMediaBundle.php for an
// example.
$mediaBundle = new MediaBundle();
$mediaBundle->data = $html5Zip;
$mediaBundle->entryPoint = 'carousel/index.html';
$mediaBundle->type = 'MEDIA_BUNDLE';
// Create the template elements for the ad. You can refer to
// https://developers.google.com/adwords/api/docs/appendix/templateads
// for the list of avaliable template fields.
$media = new TemplateElementField();
$media->name = 'Custom_layout';
$media->fieldMedia = $mediaBundle;
$media->type = 'MEDIA_BUNDLE';
$layout = new TemplateElementField();
$layout->name = 'layout';
$layout->fieldText = 'Custom';
$layout->type = 'ENUM';
$adData = new TemplateElement();
$adData->uniqueName = 'adData';
$adData->fields = array($media, $layout);
$html5Ad->templateElements = array($adData);
// Create the ad group ad.
$html5AdGroupAd = new AdGroupAd();
$html5AdGroupAd->adGroupId = $adGroupId;
$html5AdGroupAd->ad = $html5Ad;
// Optional: Set the status.
$html5AdGroupAd->status = 'PAUSED';
// Create the operation.
$operation = new AdGroupAdOperation();
$operation->operator = 'ADD';
$operation->operand = $html5AdGroupAd;
$operations = array($operation);
// Create the ads.
$result = $adGroupAdService->mutate($operations);
foreach ($result->value as $adGroupAd) {
printf("New HTML5 ad with ID %d and display URL '%s' was created.\n", $adGroupAd->ad->id, $adGroupAd->ad->displayUrl);
}
}
示例3: UploadMediaBundleExample
/**
* Runs the example.
* @param AdWordsUser $user the user to run the example with
*/
function UploadMediaBundleExample(AdWordsUser $user)
{
// Get the service, which loads the required classes.
$mediaService = $user->GetService('MediaService', ADWORDS_VERSION);
// Create HTML5 media.
$html5Zip = new MediaBundle();
$html5Zip->data = MediaUtils::GetBase64Data('https://goo.gl/9Y7qI2');
$html5Zip->type = 'MEDIA_BUNDLE';
// Make the upload request.
$result = $mediaService->upload(array($html5Zip));
// Display result.
$mediaBundle = $result[0];
$dimensions = MapUtils::GetMap($mediaBundle->dimensions);
printf("HTML5 media with ID %d, dimensions '%dx%d', MIME type '%s' was " . "uploaded.\n", $mediaBundle->mediaId, $dimensions['FULL']->width, $dimensions['FULL']->height, $mediaBundle->mimeType);
}
示例4: UploadImageExample
/**
* Runs the example.
* @param AdWordsUser $user the user to run the example with
*/
function UploadImageExample(AdWordsUser $user)
{
// Get the service, which loads the required classes.
$mediaService = $user->GetService('MediaService', ADWORDS_VERSION);
// Create image.
$image = new Image();
$image->data = MediaUtils::GetBase64Data('http://goo.gl/HJM3L');
$image->type = 'IMAGE';
// Make the upload request.
$result = $mediaService->upload(array($image));
// Display result.
$image = $result[0];
$dimensions = MapUtils::GetMap($image->dimensions);
printf("Image with dimensions '%dx%d', MIME type '%s', and id '%s' was " . "uploaded.\n", $dimensions['FULL']->width, $dimensions['FULL']->height, $image->mimeType, $image->mediaId);
}
示例5: AddResponsiveDisplayAd
/**
* Runs the example.
* @param AdWordsUser $user the user to run the example with
* @param string $adGroupId the ID of the ad group to add the ads to
*/
function AddResponsiveDisplayAd(AdWordsUser $user, $adGroupId)
{
// Get the service, which loads the required classes.
$mediaService = $user->GetService('MediaService', ADWORDS_VERSION);
// Creates image.
$image = new Image();
$image->data = MediaUtils::GetBase64Data('https://goo.gl/3b9Wfh');
$image->type = 'IMAGE';
// Make the upload request.
$result = $mediaService->upload(array($image));
$image = $result[0];
// Get the service, which loads the required classes.
$adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION);
// Create a responsive display ad.
$responsiveDisplayAd = new ResponsiveDisplayAd();
// This ad format does not allow the creation of an image using the
// Image.data field. An image must first be created using the MediaService,
// and Image.mediaId must be populated when creating the ad.
$marketingImage = new Image();
$marketingImage->mediaId = $image->mediaId;
$responsiveDisplayAd->marketingImage = $marketingImage;
$responsiveDisplayAd->shortHeadline = 'Travel';
$responsiveDisplayAd->longHeadline = 'Travel the World';
$responsiveDisplayAd->description = 'Take to the air!';
$responsiveDisplayAd->businessName = 'Google';
$responsiveDisplayAd->finalUrls = array('http://www.example.com');
// Create ad group ad.
$adGroupAd = new AdGroupAd();
$adGroupAd->adGroupId = $adGroupId;
$adGroupAd->ad = $responsiveDisplayAd;
// Set additional settings (optional).
$adGroupAd->status = 'PAUSED';
// Create operation.
$operation = new AdGroupAdOperation();
$operation->operand = $adGroupAd;
$operation->operator = 'ADD';
$operations[] = $operation;
// Make the mutate request.
$result = $adGroupAdService->mutate($operations);
// Display results.
foreach ($result->value as $adGroupAd) {
printf("Responsive display ad with ID '%d' and short headline '%s'" . " was added.\n", $adGroupAd->ad->id, $adGroupAd->ad->shortHeadline);
}
}
示例6: UploadImage
/**
* Uploads an image.
* @return float the id of the image media
*/
public function UploadImage()
{
$mediaService = $this->user->GetService('MediaService', $this->version);
$image = new Image();
$image->data = MediaUtils::GetBase64Data('http://goo.gl/HJM3L');
$image->type = 'IMAGE';
$result = $mediaService->upload(array($image));
return $result[0]->mediaId;
}
示例7: AssetCreativeTemplateVariableValue
// Set the image asset.
$imageVariableValue = new AssetCreativeTemplateVariableValue();
$imageVariableValue->uniqueName = 'Image';
$imageVariableValue->fileName = 'image' . uniqid() . '.png';
$imageVariableValue->assetByteArray = MediaUtils::GetBase64Data('https://lh4.ggpht.com/GIGNKdGHMEHFDw6TM2bgAUDK' . 'PQQRIReKZPqEpMeEhZOPYnTdOQGaSpGSEZflIFs0iw=h300');
$nativeAppInstallCreative->creativeTemplateVariableValues[] = $imageVariableValue;
// Set the price.
$priceVariableValue = new StringCreativeTemplateVariableValue();
$priceVariableValue->uniqueName = 'Price';
$priceVariableValue->value = 'Free';
$nativeAppInstallCreative->creativeTemplateVariableValues[] = $priceVariableValue;
// Set app icon image asset.
$appIconVariableValue = new AssetCreativeTemplateVariableValue();
$appIconVariableValue->uniqueName = 'Appicon';
$appIconVariableValue->fileName = 'icon' . uniqid() . '.png';
$appIconVariableValue->assetByteArray = MediaUtils::GetBase64Data('https://lh6.ggpht.com/Jzvjne5CLs6fJ1MHF-XeuUfp' . 'ABzl0YNMlp4RpHnvPRCIj4--eTDwtyouwUDzVVekXw=w300');
$nativeAppInstallCreative->creativeTemplateVariableValues[] = $appIconVariableValue;
// Set the call to action text.
$callToActionVariableValue = new StringCreativeTemplateVariableValue();
$callToActionVariableValue->uniqueName = 'Calltoaction';
$callToActionVariableValue->value = 'Install';
$nativeAppInstallCreative->creativeTemplateVariableValues[] = $callToActionVariableValue;
// Set the star rating.
$starRatingVariableValue = new StringCreativeTemplateVariableValue();
$starRatingVariableValue->uniqueName = 'Starrating';
$starRatingVariableValue->value = '4';
$nativeAppInstallCreative->creativeTemplateVariableValues[] = $starRatingVariableValue;
// Set the store type.
$storeVariableValue = new StringCreativeTemplateVariableValue();
$storeVariableValue->uniqueName = 'Store';
$storeVariableValue->value = 'Google Play';
示例8: TemplateCreative
// Get the CreativeService.
$creativeService = $user->GetService('CreativeService', 'v201511');
// Use the image banner with optional third party tracking template.
$creativeTemplateId = 10000680;
// Create the local custom creative object.
$templateCreative = new TemplateCreative();
$templateCreative->name = 'Template creative' . uniqid();
$templateCreative->advertiserId = $advertiserId;
$templateCreative->creativeTemplateId = $creativeTemplateId;
// Set the creative size.
$templateCreative->size = new Size(300, 250, false);
// Create the asset variable value.
$assetVariableValue = new AssetCreativeTemplateVariableValue();
$assetVariableValue->uniqueName = 'Imagefile';
$asset = new CreativeAsset();
$asset->assetByteArray = MediaUtils::GetBase64Data('http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg');
// Filenames must be unique.
$asset->fileName = sprintf('image%s.jpg', uniqid());
$assetVariableValue->asset = $asset;
$templateCreative->creativeTemplateVariableValues[] = $assetVariableValue;
// Create the image width variable value.
$imageWidthVariableValue = new LongCreativeTemplateVariableValue();
$imageWidthVariableValue->uniqueName = 'Imagewidth';
$imageWidthVariableValue->value = 300;
$templateCreative->creativeTemplateVariableValues[] = $imageWidthVariableValue;
// Create the image height variable value.
$imageHeightVariableValue = new LongCreativeTemplateVariableValue();
$imageHeightVariableValue->uniqueName = 'Imageheight';
$imageHeightVariableValue->value = 250;
$templateCreative->creativeTemplateVariableValues[] = $imageHeightVariableValue;
// Create the URL variable value.
示例9: array
// Log SOAP XML request and response.
$user->LogDefaults();
// Get the CreativeService.
$creativeService = $user->GetService('CreativeService', 'v201107');
// Set the ID of the advertiser (company) that all creatives will be
// assigned to.
$advertiserId = (double) 'INSERT_ADVERTISER_COMPANY_ID_HERE';
// 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";
}
}
示例10: AddClickToDownloadAd
/**
* Runs the example.
* @param AdWordsUser $user the user to run the example with
* @param string $adGroupId the ID of the ad group to add the ad to
*/
function AddClickToDownloadAd(AdWordsUser $user, $adGroupId)
{
// Get the AdGroupAdService, which loads the required classes.
$adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION);
// Optionally specify a landscape image. The image needs to be in a BASE64
// encoded form. Here we download a demo image and encode it for this ad.
$imageData = MediaUtils::GetBase64Data('http://goo.gl/9JmyKk');
// Create the template ad.
$clickToDownloadAppAd = new TemplateAd();
$clickToDownloadAppAd->name = 'Ad for demo game';
$clickToDownloadAppAd->templateId = 353;
$clickToDownloadAppAd->finalUrls = array('http://play.google.com/store/apps/details?id=com.example.demogame');
$clickToDownloadAppAd->displayUrl = 'play.google.com';
// Create the template elements for the ad. You can refer to
// https://developers.google.com/adwords/api/docs/appendix/templateads
// for the list of avaliable template fields.
$headline = new TemplateElementField();
$headline->name = 'headline';
$headline->fieldText = 'Enjoy your drive in Mars';
$headline->type = 'TEXT';
$description1 = new TemplateElementField();
$description1->name = 'description1';
$description1->fieldText = 'Realistic physics simulation';
$description1->type = 'TEXT';
$description2 = new TemplateElementField();
$description2->name = 'description2';
$description2->fieldText = 'Race against players online';
$description2->type = 'TEXT';
$appId = new TemplateElementField();
$appId->name = 'appId';
$appId->fieldText = 'com.example.demogame';
$appId->type = 'TEXT';
$appStore = new TemplateElementField();
$appStore->name = 'appStore';
$appStore->fieldText = '2';
$appStore->type = 'ENUM';
$landscapeImage = new TemplateElementField();
$landscapeImage->name = 'landscapeImage';
$landscapeImage->fieldMedia = new Image($imageData);
$landscapeImage->type = 'IMAGE';
$adData = new TemplateElement();
$adData->uniqueName = 'adData';
$adData->fields = array($headline, $description1, $description2, $appId, $appStore, $landscapeImage);
$clickToDownloadAppAd->templateElements = array($adData);
// Create the adgroupad.
$clickToDownloadAppAdGroupAd = new AdGroupAd();
$clickToDownloadAppAdGroupAd->adGroupId = $adGroupId;
$clickToDownloadAppAdGroupAd->ad = $clickToDownloadAppAd;
// Optional: Set the status.
$clickToDownloadAppAdGroupAd->status = 'PAUSED';
// Create the operation.
$operation = new AdGroupAdOperation();
$operation->operator = 'ADD';
$operation->operand = $clickToDownloadAppAdGroupAd;
$operations = array($operation);
// Create the ads.
$result = $adGroupAdService->mutate($operations);
foreach ($result->value as $adGroupAd) {
printf('New click-to-download ad with ID = %d and URL = "%s" ' . "was created.\n", $adGroupAd->ad->id, $adGroupAd->ad->finalUrls[0]);
}
}
示例11: event_InitSkinParse
public function event_InitSkinParse(&$data)
{
global $blogid;
if (MediaUtils::$blogid == 0) {
MediaUtils::$blogid = $blogid;
MediaUtils::$bshortname = MediaUtils::$blogs[MediaUtils::$blogid];
}
return;
}
示例12: dfp
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";
}
}
示例13: syncFilesystem
public static function syncFilesystem($root, $dest, $maxwidth, $maxheight)
{
$logs = array();
$root = rtrim($root, '/');
if (!$root || !file_exists($root)) {
return FALSE;
}
if (!MediaUtils::checkDir(rtrim($root, '/') . '/' . trim($dest, '/'))) {
return FALSE;
}
echo "<ul>\n";
$media = MediaUtils::getMediaList($root);
$targets = array();
$count = 1;
foreach ($media as $medium) {
ob_flush();
flush();
if ($count > self::$max_sync) {
break;
}
if (FALSE === ($destination = self::getThumbPath($medium)) || file_exists(rtrim($root, '/') . '/' . $destination)) {
continue;
}
if (FALSE === $medium->setResampledSize($maxwidth, $maxheight) || !MediaUtils::storeResampledImage($root, $destination, $medium)) {
echo "<li>Fail: {$medium->name}</li>\n";
} else {
echo "<li>Success: {$medium->name}</li>\n";
$count++;
}
}
echo "</ul>\n";
flush();
return TRUE;
}