Google-Ads-AdWords-Client

 view release on metacpan or  search on metacpan

examples/v201809/advanced_operations/add_gmail_ad.pl  view on Meta::CPAN

      finalUrls                 => ["http://www.example.com/"]
  });

  # Create ad group ad for the Gmail ad.
  my $gmail_ad_group_ad = Google::Ads::AdWords::v201809::AdGroupAd->new({
    adGroupId => $ad_group_id,
    ad        => $gmail_ad,
    # Additional properties (non-required).
    status => "PAUSED"
  });

  # Create operation.
  my $gmail_ad_group_ad_operation =
    Google::Ads::AdWords::v201809::AdGroupAdOperation->new({
      operator => "ADD",
      operand  => $gmail_ad_group_ad
    });

  # Add Gmail ad.
  my $result =
    $client->AdGroupAdService()
    ->mutate({operations => [$gmail_ad_group_ad_operation]});

  # Display results.
  if ($result->get_value()) {
    foreach my $ad_group_ad (@{$result->get_value()}) {
      printf "New Gmail ad with ID %d and headline \"%s\" was added.\n",
        $ad_group_ad->get_ad()->get_id(),
        $ad_group_ad->get_ad()->get_teaser()->get_headline();
    }
  } else {
    print "No Gmail ads were added.\n";
    return 0;
  }

  return 1;
}

sub _upload_image {
  my ($client, $url) = @_;

  # Creates an image and upload it to the server.
  my $image_data =
    Google::Ads::Common::MediaUtils::get_base64_data_from_url($url);
  my $image = Google::Ads::AdWords::v201809::Image->new({
    data => $image_data,
    type => "IMAGE"
  });

  return $client->MediaService()->upload({media => [$image]});
}

# Don't run the example if the file is being included.
if (abs_path($0) ne abs_path(__FILE__)) {
  return 1;
}

# Log SOAP XML request, response and API errors.
Google::Ads::AdWords::Logging::enable_all_logging(1);

# Get AdWords Client, credentials will be read from ~/adwords.properties.
my $client = Google::Ads::AdWords::Client->new({version => "v201809"});

# By default examples are set to die on any server returned fault.
$client->set_die_on_faults(1);

# Call the example
add_gmail_ad($client, $ad_group_id);



( run in 0.755 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )