GOOGLE-ADWORDS-PERL-CLIENT

 view release on metacpan or  search on metacpan

examples/v201309/advanced_operations/use_shared_bidding_strategy.pl  view on Meta::CPAN

  my @operations = ();

  # Create campaign.
  my $campaign = Google::Ads::AdWords::v201309::Campaign->new({
    name => 'Interplanetary Cruise #' . uniqid(),
    budget => Google::Ads::AdWords::v201309::Budget->new({
      budgetId => $budget_id
    }),
    # Set bidding strategy (required).
    biddingStrategyConfiguration =>
        Google::Ads::AdWords::v201309::BiddingStrategyConfiguration->new({
          biddingStrategyId => $bidding_strategy_id
        }),
    # Set keyword matching setting (required).
    settings => [
        Google::Ads::AdWords::v201309::KeywordMatchSetting->new({
          optIn => 0
        })
    ],
    # Network targeting (recommended).
    networkSetting => Google::Ads::AdWords::v201309::NetworkSetting->new({
      targetGoogleSearch => 1,
      targetSearchNetwork => 1,
      targetContentNetwork => 1
    })
  });

  # Create operation.
  my $operation = Google::Ads::AdWords::v201309::CampaignOperation->new({
    operator => 'ADD',
    operand => $campaign
  });

  push @operations, $operation;

  my $result = $client->CampaignService()->mutate({
    operations => \@operations
  });

  if ($result->get_value()) {
    my $new_campaign = $result->get_value()->[0];
    printf "Campaign with name \"%s\", ID %d and bidding strategy ID %d was "
        . "created.\n", $new_campaign->get_name(), $new_campaign->get_id(),
          $new_campaign->get_biddingStrategyConfiguration()
              ->get_biddingStrategyId();
    return $new_campaign;
  } else {
    print "No campaigns were added.\n";
    return 0;
  }
}

# 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();

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

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

# Call the example
use_shared_bidding_strategy($client, $budget_id);



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