Here's how to create a Video creative :
Java
// Provide the parent advertiser ID to create the creative under. long advertiserId = advertiser - id ; // Provide the display name of the creative. String displayName = display - name ; // Provide the media ID of the uploaded video file. long videoMediaId = video - media - id ; // Provide the URL of the page that the creative redirects to and the name // of the click tag used in the exit event. String exitEventUrl = exit - event - url ; String exitEventName = exit - event - name ; // Create a creative object. Creative creative = new Creative () . setDisplayName ( displayName ) . setEntityStatus ( "ENTITY_STATUS_ACTIVE" ) . setHostingSource ( "HOSTING_SOURCE_HOSTED" ) . setCreativeType ( "CREATIVE_TYPE_VIDEO" ); // Assign the video asset to a role. AssetAssociation assetAssociation = new AssetAssociation () . setAsset ( new Asset (). setMediaId ( videoMediaId )) . 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 () . setName ( exitEventName ) . setType ( "EXIT_EVENT_TYPE_DEFAULT" ) . setUrl ( exitEventUrl ); // 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 ( advertiserId , creative ); // Send the request. Creative response = request . execute (); // Display ID of the new creative. System . out . printf ( "Creative was created with ID %s." , response . getCreativeId ());
Python
# Provide the parent advertiser ID to create the creative under. advertiser_id = advertiser - id # Provide the display name of the creative. display_name = display - name # Provide the media ID of the uploaded video file. video_media_id = video - media - id # Provide the URL of the page that the creative redirects to and the name of the # click tag used in the exit event. exit_event_url = exit - event - url exit_event_name = exit - event - name # Build the creative object. creative_obj = { "displayName" : display_name , "entityStatus" : "ENTITY_STATUS_ACTIVE" , "hostingSource" : "HOSTING_SOURCE_HOSTED" , "creativeType" : "CREATIVE_TYPE_VIDEO" , "assets" : [{ "asset" : { "mediaId" : video_media_id }, "role" : "ASSET_ROLE_MAIN" , }], "exitEvents" : [{ "name" : exit_event_name , "type" : "EXIT_EVENT_TYPE_DEFAULT" , "url" : exit_event_url , }], } # Create the creative. creative_response = ( service . advertisers () . creatives () . create ( advertiserId = advertiser_id , body = creative_obj ) . execute () ) # Print the resulting creative ID. print ( f 'Creative was created with ID { creative_response [ "creativeId" ] } .' )
PHP
// Provide the parent advertiser ID to create the creative under. $advertiserId = advertiser-id ; // Provide the display name of the creative. $displayName = display-name ; // Provide the media ID of the uploaded video file. $videoMediaId = video-media-id ; // Provide the URL of the page that the creative redirects to and the name // of the click tag used in the exit event. $exitEventUrl = exit-event-url ; $exitEventName = exit-event-name ; // Create a creative object. $creative = new Google_Service_DisplayVideo_Creative(); $creative->setDisplayName($displayName); $creative->setEntityStatus('ENTITY_STATUS_ACTIVE'); $creative->setHostingSource('HOSTING_SOURCE_HOSTED'); $creative->setCreativeType('CREATIVE_TYPE_VIDEO'); // Create an exit event. $exitEvent = new Google_Service_DisplayVideo_ExitEvent(); $exitEvent->setName($exitEventName); $exitEvent->setType('EXIT_EVENT_TYPE_DEFAULT'); $exitEvent->setUrl($exitEventUrl); $creative->setExitEvents(array($exitEvent)); // Assign the video asset to a role. $assetAssociation = new Google_Service_DisplayVideo_AssetAssociation(); $asset = new Google_Service_DisplayVideo_Asset(); $asset->setMediaId($videoMediaId); $assetAssociation->setAsset($asset); $assetAssociation->setRole('ASSET_ROLE_MAIN'); $creative->setAssets(array($assetAssociation)); // Upload and set the asset and create the video creative under the // given advertiser. try { $result = $this->service->advertisers_creatives->create( $advertiserId, $creative ); } catch (\Exception $e) { $this->renderError($e); return; } // Display ID of the new creative. printf('<p>Creative was created with ID %s.</p>', $result['creativeId']);

