สร้างและอัปโหลดครีเอทีฟโฆษณา

คู่มือนี้จะอธิบายวิธีอัปโหลดชิ้นงานครีเอทีฟโฆษณาและสร้าง ดิสเพลย์และ วิดีโอ 360 แหล่งข้อมูล Creative รายการที่ใช้เครือข่ายดิสเพลย์และ API ของวิดีโอ 360 advertisers.assets และ advertisers.creatives บริการ

ข้อกำหนดเบื้องต้น

ทำตามขั้นตอนต่อไปนี้ก่อนสร้างครีเอทีฟโฆษณาโดยใช้ Display & API ของวิดีโอ 360

  1. สร้างและให้สิทธิ์โปรเจ็กต์ API

  2. ตรวจสอบว่าโฆษณาแบบดิสเพลย์และ โปรไฟล์ผู้ใช้ Video 360 ที่ระบุโดยผู้ใช้หรือบริการ ที่อยู่อีเมลของบัญชีได้ อ่านและ เขียนสิทธิ์สำหรับ ผู้ลงโฆษณา หากคุณไม่มีอ่านและ เขียน โปรดติดต่อ ผู้ใช้ผู้ดูแลระบบในทีมของคุณ

สร้างครีเอทีฟโฆษณาใหม่

การสร้างครีเอทีฟโฆษณาใหม่ด้วยชิ้นงานใหม่ผ่านดิสเพลย์และ Video 360 API ต้องใช้ที่ คำขอ API อย่างน้อย 2 รายการ รายการแรกจะอัปโหลดชิ้นงานครีเอทีฟโฆษณา และชิ้นงานที่ 2 จะสร้างออบเจ็กต์ครีเอทีฟโฆษณา

อัปโหลดชิ้นงาน

เพื่ออัปโหลดครีเอทีฟโฆษณาที่จำเป็น assets ไปยังดิสเพลย์และ Video 360, เรียกเมธอด advertisers.assets.upload

คุณต้องกำหนดชิ้นงานให้กับผู้ลงโฆษณาเดียวกันกับครีเอทีฟโฆษณา

หลังจากที่คุณอัปโหลดชิ้นงานแล้ว API จะแสดงการตอบกลับที่ รวมออบเจ็กต์ asset คุณเรียกออบเจ็กต์ asset นี้ไม่ได้ อีกครั้งในภายหลัง ดังนั้นให้จดบันทึก mediaId ที่เกี่ยวข้อง mediaId ของเนื้อหานี้ใช้เพื่อกำหนดเนื้อหาให้กับ ครีเอทีฟโฆษณา

ครีเอทีฟโฆษณาบางประเภทจะยอมรับไฟล์บางประเภทเป็นเนื้อหาโดยเฉพาะ บทบาทเนื้อหา ดูศูนย์ช่วยเหลือสำหรับข้อมูลเพิ่มเติมเกี่ยวกับ การเลือกประเภทไฟล์ที่เหมาะสมสำหรับครีเอทีฟโฆษณาของคุณ

ตัวอย่างวิธีอัปโหลดชิ้นงานมีดังนี้

JavaPythonPHPcURL
// Create the asset upload request content.
CreateAssetRequest content = new CreateAssetRequest();
content
.setFilename(asset-filename);

// Create input stream for the creative asset.
InputStreamContent assetStream = new InputStreamContent(
   getMimeType
(asset-filename),
   
new FileInputStream(asset-path));

// Configure the asset upload request.
Assets.Upload assetRequest = service.advertisers().assets()
   
.upload(advertiser-id, content, assetStream);

// Upload the asset.
CreateAssetResponse assetResponse = assetRequest.execute();

// Display the new asset media ID.
Asset asset = assetResponse.getAsset();
System.out.printf("The asset has been upload with media ID %s",
   asset
.getMediaId());

ตัวอย่างนี้ใช้ฟังก์ชันตัวช่วยต่อไปนี้ในการค้นหาไฟล์ MIME ประเภท:

import java.net.FileNameMap;
import java.net.URLConnection;

private static String getMimeType(String fileName) {

 
// Parse filename for appropriate MIME type.
 
FileNameMap fileNameMap = URLConnection.getFileNameMap();
 
String mimeType = fileNameMap.getContentTypeFor(fileName);

 
// If MIME type was found, return it.
 
if (mimeType != null) {
   
return mimeType;
 
}

 
// Otherwise, return a default value.
 
return "application/octet-stream";
}
# Create the request body.
body
= {
   
'filename': asset-filename
}

# Create upload object.
media
= MediaFileUpload(asset-path)
if not media.mimetype():
  media
= MediaFileUpload(asset-path, 'application/octet-stream')

# Upload the asset.
response
= service.advertisers().assets().upload(
    advertiserId
=advertiser-id,
    body
=body,
    media_body
=media
).execute()

# Display the new asset media ID.
print("Asset was created with media ID %s." % response['asset']['mediaId'])
$body = new Google_Service_DisplayVideo_CreateAssetRequest();
$body
->setFilename(asset-filename);

$optParams
= array(
   
'data' => file_get_contents(asset-path),
   
'mimeType' => mime_content_type(asset-filename),
   
'uploadType' => 'media'
);

// Call the API, uploading the asset file to Display & Video 360.
$result
= $service->advertisers_assets->upload(
   
advertiser-id,
    $body
,
    $optParams
);

// Display the new asset media ID.
printf
(
   
'Asset was created with media ID %s.',
    $result
->getAsset()->getMediaId()
);
curl --request POST \
 
'https://displayvideo.googleapis.com/upload/v3/advertisers/advertiser-id/assets?uploadType=multipart'
 
--header 'Authorization: Bearer access-token' \
   
-F "data={\"filename\": \"asset-filename\"};type=application/json;charset=UTF-8" \
   
-F "file=@asset-path;type=asset-mime-type"

สร้างครีเอทีฟโฆษณา

หลังจากที่คุณอัปโหลดเนื้อหาและได้รับรหัสสื่อแล้ว คุณสามารถสร้าง Creative ที่มีชิ้นงานเหล่านั้น

ใช้เมธอด advertisers.creatives.create เพื่อสร้าง Creative ครีเอทีฟโฆษณาแต่ละประเภทต้องการเพียงช่องย่อยของช่อง Creative เท่านั้น

ดูรายละเอียดเกี่ยวกับการแมปช่อง UI กับ ช่อง API ที่เกี่ยวข้อง สำหรับครีเอทีฟโฆษณาแต่ละประเภท

ต่อไปนี้คือตัวอย่างวิธีสร้างครีเอทีฟโฆษณา Display แบบเนทีฟ, ครีเอทีฟโฆษณา HTML5 และวิดีโอ

โฆษณาแบบดิสเพลย์เนทีฟ

JavaPythonPHP
// Create a creative object.
Creative creative = new Creative();
creative
.setDisplayName(display-name);
creative
.setEntityStatus("ENTITY_STATUS_ACTIVE");
creative
.setHostingSource("HOSTING_SOURCE_HOSTED");

// Set native creative type.
creative
.setCreativeType("CREATIVE_TYPE_NATIVE");

// Create a dimensions object.
Dimensions dimensions = new Dimensions();
dimensions
.setHeightPixels(creative-height-pixels);
dimensions
.setWidthPixels(creative-width-pixels);

// Add the dimensions object to the creative object.
creative
.setDimensions(dimensions);

// Create list for asset associations.
List<AssetAssociation> assetAssociations = new ArrayList<AssetAssociation>();

// Assign the image asset to a role.
AssetAssociation mainImageAssetAssociation = new AssetAssociation();
mainImageAssetAssociation
.setAsset(new Asset().setMediaId(image-asset-media-id));
mainImageAssetAssociation
.setRole("ASSET_ROLE_MAIN");
assetAssociations
.add(mainImageAssetAssociation);

// Assign the logo asset to a role.
AssetAssociation iconAssetAssociation = new AssetAssociation();
iconAssetAssociation
.setAsset(new Asset().setMediaId(logo-asset-media-id));
iconAssetAssociation
.setRole("ASSET_ROLE_ICON");
assetAssociations
.add(iconAssetAssociation);

// Create and assign advertiser name asset.
Asset advertiserNameAsset = new Asset();
advertiserNameAsset
.setContent(advertiser-name);
AssetAssociation advertiserNameAssetAssociation = new AssetAssociation();
advertiserNameAssetAssociation
.setAsset(advertiserNameAsset);
advertiserNameAssetAssociation
.setRole("ASSET_ROLE_ADVERTISER_NAME");
assetAssociations
.add(advertiserNameAssetAssociation);

// Create and assign headline asset.
Asset headlineAsset = new Asset();
headlineAsset
.setContent(headline);
AssetAssociation headlineAssetAssociation = new AssetAssociation();
headlineAssetAssociation
.setAsset(headlineAsset);
headlineAssetAssociation
.setRole("ASSET_ROLE_HEADLINE");
assetAssociations
.add(headlineAssetAssociation);

// Create and assign body text asset.
Asset bodyTextAsset = new Asset();
bodyTextAsset
.setContent(body-text);
AssetAssociation bodyTextAssetAssociation = new AssetAssociation();
bodyTextAssetAssociation
.setAsset(bodyTextAsset);
bodyTextAssetAssociation
.setRole("ASSET_ROLE_BODY");
assetAssociations
.add(bodyTextAssetAssociation);

// Create and assign caption URL asset.
Asset captionUrlAsset = new Asset();
captionUrlAsset
.setContent(caption-url);
AssetAssociation captionUrlAssetAssociation = new AssetAssociation();
captionUrlAssetAssociation
.setAsset(captionUrlAsset);
captionUrlAssetAssociation
.setRole("ASSET_ROLE_CAPTION_URL");
assetAssociations
.add(captionUrlAssetAssociation);

// Create and assign call to action asset.
Asset callToActionAsset = new Asset();
callToActionAsset
.setContent(call-to-action);
AssetAssociation callToActionAssetAssociation = new AssetAssociation();
callToActionAssetAssociation
.setAsset(callToActionAsset);
callToActionAssetAssociation
.setRole("ASSET_ROLE_CALL_TO_ACTION");
assetAssociations
.add(callToActionAssetAssociation);

// Create and set the list of creative assets.
creative
.setAssets(assetAssociations);

// Create an exit event.
ExitEvent exitEvent = new ExitEvent();
exitEvent
.setType("EXIT_EVENT_TYPE_DEFAULT");
exitEvent
.setUrl(landing-page-url);

// Create and set the list of exit events for the creative.
creative
.setExitEvents(ImmutableList.of(exitEvent));

// Configure the create request.
Creatives.Create request =
   service
.advertisers().creatives().create(advertiser-id, creative);

// Send the request.
Creative response = request.execute();

// Display the new creative.
System.out.printf(
   
"Creative %s was created.\n",
   response
.getName());
# Create a creative object.
creative_obj
= {
   
'displayName': display-name,
   
'entityStatus': 'ENTITY_STATUS_ACTIVE',
   
'hostingSource': 'HOSTING_SOURCE_HOSTED',
   
'creativeType': 'CREATIVE_TYPE_NATIVE',
   
'dimensions': {
       
'heightPixels': creative-height-pixels,
       
'widthPixels': creative-width-pixels
   
},
   
'assets': [
       
{
           
'asset': {'mediaId' : image-asset-media-id},
           
'role': 'ASSET_ROLE_MAIN'
       
},
       
{
           
'asset': {'mediaId' : logo-asset-media-id},
           
'role': 'ASSET_ROLE_ICON'
       
},
       
{
           
'asset': {'content' : advertiser-name},
           
'role': 'ASSET_ROLE_ADVERTISER_NAME'
       
},
       
{
           
'asset': {'content' : headline},
           
'role': 'ASSET_ROLE_HEADLINE'
       
},
       
{
           
'asset': {'content' : body-text},
           
'role': 'ASSET_ROLE_BODY'
       
},
       
{
           
'asset': {'content' : caption-url},
             
'role': 'ASSET_ROLE_CAPTION_URL'
       
},
       
{
           
'asset': {'content' : call-to-action},
           
'role': 'ASSET_ROLE_CALL_TO_ACTION'
       
},
   
],
   
'exitEvents': [
       
{
           
'type': 'EXIT_EVENT_TYPE_DEFAULT',
           
'url': landing-page-url
       
}
   
]
}

# Create the creative.
creative
= service.advertisers().creatives().create(
   advertiserId
=advertiser-id,
   body
=creative_obj
).execute()

# Display the new creative.
print("creative %s was created." % creative["name"])
// Create a creative object.
$creative
= new Google_Service_DisplayVideo_Creative();
$creative
->setDisplayName(display-name);
$creative
->setEntityStatus('ENTITY_STATUS_ACTIVE');
$creative
->setHostingSource('HOSTING_SOURCE_HOSTED');

// Set native creative type.
$creative
->setCreativeType('CREATIVE_TYPE_NATIVE');

// Create a dimensions object.
$dimensions
= new Google_Service_DisplayVideo_Dimensions();
$dimensions
->setHeightPixels(creative-height-pixels);
$dimensions
->setWidthPixels(creative-width-pixels);

// Add the dimensions object to the creative object.
$creative
->setDimensions($dimensions);

// Create list for asset associations.
$assetAssociations
= array();

// Assign the image asset to a role.
$imageAssetAssoc
= new Google_Service_DisplayVideo_AssetAssociation();
$imageAsset
= new Google_Service_DisplayVideo_Asset();
$imageAsset
->setMediaId(image-asset-media-id);
$imageAssetAssoc
->setAsset($imageAsset);
$imageAssetAssoc
->setRole('ASSET_ROLE_MAIN');
$assetAssociations
[] = $imageAssetAssoc;

// Assign the logo asset to a role.
$iconAssetAssoc
= new Google_Service_DisplayVideo_AssetAssociation();
$iconAsset
= new Google_Service_DisplayVideo_Asset();
$iconAsset
->setMediaId(logo-asset-media-id);
$iconAssetAssoc
->setAsset($iconAsset);
$iconAssetAssoc
->setRole('ASSET_ROLE_ICON');
$assetAssociations
[] = $iconAssetAssoc;

// Create and assign advertiser name asset.
$advNameAssetAssoc
= new Google_Service_DisplayVideo_AssetAssociation();
$advNameAsset
= new Google_Service_DisplayVideo_Asset();
$advNameAsset
->setContent(advertiser-name);
$advNameAssetAssoc
->setAsset($advNameAsset);
$advNameAssetAssoc
->setRole('ASSET_ROLE_ADVERTISER_NAME');
$assetAssociations
[] = $advNameAssetAssoc;

// Create and assign headline asset.
$headlineAssetAssoc
= new Google_Service_DisplayVideo_AssetAssociation();
$headlineAsset
= new Google_Service_DisplayVideo_Asset();
$headlineAsset
->setContent(headline);
$headlineAssetAssoc
->setAsset($headlineAsset);
$headlineAssetAssoc
->setRole('ASSET_ROLE_HEADLINE');
$assetAssociations
[] = $headlineAssetAssoc;

// Create and assign body text asset.
$bodyTextAssetAssoc
= new Google_Service_DisplayVideo_AssetAssociation();
$bodyTextAsset
= new Google_Service_DisplayVideo_Asset();
$bodyTextAsset
->setContent(body-text);
$bodyTextAssetAssoc
->setAsset($bodyTextAsset);
$bodyTextAssetAssoc
->setRole('ASSET_ROLE_BODY');
$assetAssociations
[] = $bodyTextAssetAssoc;

// Create and assign caption URL asset.
$captionUrlAssetAssoc
= new Google_Service_DisplayVideo_AssetAssociation();
$captionUrlAsset
= new Google_Service_DisplayVideo_Asset();
$captionUrlAsset
->setContent(caption-url);
$captionUrlAssetAssoc
->setAsset($captionUrlAsset);
$captionUrlAssetAssoc
->setRole('ASSET_ROLE_CAPTION_URL');
$assetAssociations
[] = $captionUrlAssetAssoc;

// Create and assign call to action asset.
$cToAAssetAssoc
= new Google_Service_DisplayVideo_AssetAssociation();
$cToAAsset
= new Google_Service_DisplayVideo_Asset();
$cToAAsset
->setContent(call-to-action);
$cToAAssetAssoc
->setAsset($cToAAsset);
$cToAAssetAssoc
->setRole('ASSET_ROLE_CALL_TO_ACTION');
$assetAssociations
[] = $cToAAssetAssoc;

// Set the list of creative assets.
$creative
->setAssets($assetAssociations);

// Create an exit event.
$exitEvent
= new Google_Service_DisplayVideo_ExitEvent();
$exitEvent
->setType('EXIT_EVENT_TYPE_DEFAULT');
$exitEvent
->setUrl(landing-page-url);

// Create and set the list of exit events for the creative.
$creative
->setExitEvents(array($exitEvent));

// Send the create request.
$result
= $this->service->advertisers_creatives->create(
   
advertiser-id,
    $creative
);

printf
('Creative %s was created.', $result['name']);

HTML5

JavaPythonPHP
// Create a creative object.
Creative creative = new Creative();
creative
.setDisplayName(display-name);
creative
.setEntityStatus("ENTITY_STATUS_ACTIVE");
creative
.setHostingSource("HOSTING_SOURCE_HOSTED");

// Set standard creative type.
creative
.setCreativeType("CREATIVE_TYPE_STANDARD");

// Create a dimensions object.
Dimensions dimensions = new Dimensions();
dimensions
.setHeightPixels(creative-height-pixels);
dimensions
.setWidthPixels(creative-width-pixels);

// Add the dimensions object to the creative object.
creative
.setDimensions(dimensions);

// Assign the HTML5 asset to a role.
AssetAssociation assetAssociation = new AssetAssociation();
assetAssociation
.setAsset(new Asset().setMediaId(html5-asset-media-id));
assetAssociation
.setRole("ASSET_ROLE_MAIN");

// Create and set the list of creative assets.
creative
.setAssets(ImmutableList.of(assetAssociation));

// Create an exit event.
ExitEvent exitEvent = new ExitEvent();
exitEvent
.setName(exit-event-name);
exitEvent
.setType("EXIT_EVENT_TYPE_DEFAULT");
exitEvent
.setUrl(exit-event-url);

// Create and set the list of exit events for the creative.
creative
.setExitEvents(ImmutableList.of(exitEvent));

// Configure the create request.
Creatives.Create request =
   service
.advertisers().creatives().create(advertiser-id, creative);

// Send the request.
Creative response = request.execute();

// Display the new creative.
System.out.printf(
   
"Creative %s was created.\n",
   response
.getName());
# Create a creative object.
creative_obj
= {
   
'displayName': display-name,
   
'entityStatus': 'ENTITY_STATUS_ACTIVE',
   
'hostingSource': 'HOSTING_SOURCE_HOSTED',
   
'creativeType': 'CREATIVE_TYPE_STANDARD',
   
'dimensions': {
       
'heightPixels': creative-height-pixels,
       
'widthPixels': creative-width-pixels
   
},
   
'assets': [
       
{
           
'asset': {'mediaId' : html5-asset-media-id},
           
'role': 'ASSET_ROLE_MAIN'
       
}
   
],
   
'exitEvents': [
       
{
           
'name': exit-event-name,
           
'type': 'EXIT_EVENT_TYPE_DEFAULT',
           
'url': exit-event-url
       
}
   
]
}

# Create the creative.
creative
= service.advertisers().creatives().create(
   advertiserId
=advertiser-id,
   body
=creative_obj
).execute()

# Display the new creative.
print("Creative %s was created." % creative["name"])
// Create a creative object.
$creative
= new Google_Service_DisplayVideo_Creative();
$creative
->setDisplayName(display-name);
$creative
->setEntityStatus('ENTITY_STATUS_ACTIVE');
$creative
->setHostingSource('HOSTING_SOURCE_HOSTED');

// Set standard creative type.
$creative
->setCreativeType('CREATIVE_TYPE_STANDARD');

// Create a dimensions object.
$dimensions
= new Google_Service_DisplayVideo_Dimensions();
$dimensions
->setHeightPixels(creative-height-pixels);
$dimensions
->setWidthPixels(creative-width-pixels);

// Add the dimensions object to the creative object.
$creative
->setDimensions($dimensions);

// Assign the HTML asset to a role.
$htmlAssetAssoc
= new Google_Service_DisplayVideo_AssetAssociation();
$htmlAsset
= new Google_Service_DisplayVideo_Asset();
$htmlAsset
->setMediaId(html5-asset-media-id);
$htmlAssetAssoc
->setAsset($htmlAsset);
$htmlAssetAssoc
->setRole('ASSET_ROLE_MAIN');

// Create and set the list of creative assets.
$creative
->setAssets(array($htmlAssetAssoc));

// Create an exit event.
$exitEvent
= new Google_Service_DisplayVideo_ExitEvent();
$exitEvent
->setName(exit-event-name);
$exitEvent
->setType('EXIT_EVENT_TYPE_DEFAULT');
$exitEvent
->setUrl(exit-event-url);

// Create and set the list of exit events for the creative.
$creative
->setExitEvents(array($exitEvent));

// Send the create request.
$result
= $this->service->advertisers_creatives->create(
   
advertiser-id,
    $creative
);

printf
('Creative %s was created.', $result['name']);

วิดีโอ

JavaPythonPHP
// Create a creative object.
Creative creative = new Creative();
creative
.setDisplayName(display-name);
creative
.setEntityStatus("ENTITY_STATUS_ACTIVE");
creative
.setHostingSource("HOSTING_SOURCE_HOSTED");

// Set video creative type.
creative
.setCreativeType("CREATIVE_TYPE_VIDEO");

// Assign the video asset to a role.
AssetAssociation assetAssociation = new AssetAssociation();
assetAssociation
.setAsset(new Asset().setMediaId(video-asset-media-id));
assetAssociation
.setRole("ASSET_ROLE_MAIN");

// Create and set the list of creative assets.
creative
.setAssets(ImmutableList.of(assetAssociation));

// Create an exit event.
ExitEvent exitEvent = new ExitEvent();
exitEvent
.setName(exit-event-name);
exitEvent
.setType("EXIT_EVENT_TYPE_DEFAULT");
exitEvent
.setUrl(exit-event-url);

// Create and set the list of exit events for the creative.
creative
.setExitEvents(ImmutableList.of(exitEvent));

// Configure the create request.
Creatives.Create request =
   service
.advertisers().creatives().create(advertiser-id, creative);

// Send the request.
Creative response = request.execute();

// Display the new creative.
System.out.printf(
   
"Creative %s was created.\n",
   response
.getName());
# Create a creative object.
creative_obj
= {
   
'displayName': display-name,
   
'entityStatus': 'ENTITY_STATUS_ACTIVE',
   
'hostingSource': 'HOSTING_SOURCE_HOSTED',
   
'creativeType': 'CREATIVE_TYPE_VIDEO',
   
'assets': [
       
{
           
'asset': {'mediaId' : video-asset-media-id},
           
'role': 'ASSET_ROLE_MAIN'
       
}
   
],
   
'exitEvents': [
       
{
           
'name': exit-event-name,
           
'type': 'EXIT_EVENT_TYPE_DEFAULT',
           
'url': exit-event-url
       
}
   
]
}

# Create the creative.
creative
= service.advertisers().creatives().create(
   advertiserId
=advertiser-id,
   body
=creative_obj
).execute()

# Display the new creative.
print("creative %s was created." % creative["name"])
// Create a creative object.
$creative
= new Google_Service_DisplayVideo_Creative();
$creative
->setDisplayName(display-name);
$creative
->setEntityStatus('ENTITY_STATUS_ACTIVE');
$creative
->setHostingSource('HOSTING_SOURCE_HOSTED');

// Set video creative type.
$creative
->setCreativeType('CREATIVE_TYPE_VIDEO');

// Assign the video asset to a role.
$videoAssetAssoc
= new Google_Service_DisplayVideo_AssetAssociation();
$videoAsset
= new Google_Service_DisplayVideo_Asset();
$videoAsset
->setMediaId(video-asset-media-id);
$videoAssetAssoc
->setAsset($videoAsset);
$videoAssetAssoc
->setRole('ASSET_ROLE_MAIN');

// Create and set the list of creative assets.
$creative
->setAssets(array($videoAssetAssoc));

// Create an exit event.
$exitEvent
= new Google_Service_DisplayVideo_ExitEvent();
$exitEvent
->setName(exit-event-name);
$exitEvent
->setType('EXIT_EVENT_TYPE_DEFAULT');
$exitEvent
->setUrl(exit-event-url);

// Create and set the list of exit events for the creative.
$creative
->setExitEvents(array($exitEvent));

// Send the create request.
$result
= $this->service->advertisers_creatives->create(
   
advertiser-id,
    $creative
);

printf
('Creative %s was created.', $result['name']);