Google-Ads-GoogleAds-Client
view release on metacpan or search on metacpan
examples/advanced_operations/add_demand_gen_campaign.pl view on Meta::CPAN
adGroupAdOperation => $ad_group_ad_operation
});
}
# [END add_demand_gen_campaign_4]
# Create a mutate operation that creates a new image asset.
sub create_image_asset_operation {
my ($asset_resource_name, $url, $asset_name) = @_;
my $image_content = get_base64_data_from_url($url);
my $asset_operation =
Google::Ads::GoogleAds::V24::Services::AssetService::AssetOperation->new({
create => Google::Ads::GoogleAds::V24::Resources::Asset->new({
resourceName => $asset_resource_name,
imageAsset => Google::Ads::GoogleAds::V24::Common::ImageAsset->new({
data => $image_content
}
),
# Provide a unique friendly name to identify your asset.
# When there is an existing image asset with the same content
# but a different name, the new name will be dropped silently.
name => $asset_name
}
),
});
return
Google::Ads::GoogleAds::V24::Services::GoogleAdsService::MutateOperation->
new({
assetOperation => $asset_operation
});
}
# Create a mutate operation that creates a new video asset.
sub create_video_asset_operation {
my ($asset_resource_name, $video_id, $asset_name) = @_;
my $asset_operation =
Google::Ads::GoogleAds::V24::Services::AssetService::AssetOperation->new({
create => Google::Ads::GoogleAds::V24::Resources::Asset->new({
resourceName => $asset_resource_name,
name => $asset_name,
youtubeVideoAsset =>
Google::Ads::GoogleAds::V24::Common::YoutubeVideoAsset->new({
youtubeVideoId => $video_id
})})});
return
Google::Ads::GoogleAds::V24::Services::GoogleAdsService::MutateOperation->
new({
assetOperation => $asset_operation
});
}
# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
return 1;
}
# Get Google Ads Client, credentials will be read from ~/googleads.properties.
my $api_client = Google::Ads::GoogleAds::Client->new();
# By default examples are set to die on any server returned fault.
$api_client->set_die_on_faults(1);
# Initialize arguments to pass to the add_demand_gen_campaign method.
my $customer_id;
my $video_id;
# Parameters passed on the command line will override any parameters set in code.
GetOptions("customer_id=s" => \$customer_id, "video_id=s" => \$video_id);
# Print the help message if the parameters are not initialized in the code nor
# in the command line.
pod2usage(2) if not check_params($customer_id);
# Call the example.
add_demand_gen_campaign($api_client, $customer_id =~ s/-//gr, $video_id);
=pod
=head1 NAME
add_demand_gen_campaign
=head1 DESCRIPTION
This example shows how to create a Demand Gen campaign with a video ad.
=head1 SYNOPSIS
add_demand_gen_campaign.pl [options]
-help Show the help message.
-customer_id The Google Ads customer ID.
-video_id The YouTube ID of a video to use in an ad.
=cut
( run in 0.470 second using v1.01-cache-2.11-cpan-f56aa216473 )