My favorites | English | Sign in

Documentation for the requested version is not available.Documentation for the requested diff is not available.

AdService

Link to this version

AdService provides operations for accessing, creating and modifying Ads in an AdGroup. Each Ad object is the visual representation of an ad. Each ad group has one or more ads, where an ad can be of many different formats (such as text ad or an image ad). An ad can be in following serving statuses: enabled, disabled, or paused. Only enabled ads will be served; a disabled or paused ad will not be served.

Ad is one of:

More Information

Requests

addAds

Make a batch of new Ads.

The adGroupId field of the Ad indicates which AdGroup to add the Ad to. The adGroupId field is required, and the indicated AdGroup must exist already.

The Ad's id and disapproved fields are set by the AdService -- if you fill them in they will be ignored.

By default, Ads are enabled and will be served as soon as they are created. You can set the status field on the ad to either paused or disabled to prevent the ad from being active.

Parameters

ads Ad[]
The new data for the Ads.

Ad is one of:

Response

Ad[] The new Ad objects, with IDs filled in.

Ad is one of:

Samples

Code sample not available.
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
      // Create new text ad structure.
      long adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");

      TextAd textAd = new TextAd();
      textAd.setAdGroupId(adGroupId);
      textAd.setAdType(AdType.TextAd);
      textAd.setHeadline("Luxury Cruise to Mars");
      textAd.setDescription1("Visit the Red Planet in style.");
      textAd.setDescription2("Low-gravity fun for everyone!");
      textAd.setDisplayUrl("www.example.com");
      textAd.setDestinationUrl("http://www.example.com");

      // Check new ad for policy violations before adding it.
      String[] languageTarget = new String[] {"en"};
      GeoTarget geoTarget = new GeoTarget();
      geoTarget.setCountryTargets(new CountryTargets(new String[] {"US"},
          new String[] {}));
      ApiError[] errors =
        service.checkAds(new Ad[] {textAd}, languageTarget, geoTarget);

      // Add text ad if there are no policy violations.
      if (errors == null) {
        Ad[] ads = service.addAds(new Ad[] {textAd});

Code sample not available.
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
        // Create new text ad structure.
        long adGroupId = long.Parse("INSERT_AD_GROUP_ID_HERE");

        TextAd textAd = new TextAd();
        textAd.adGroupId = adGroupId;
        textAd.adType = AdType.TextAd;
        textAd.adTypeSpecified = true;
        textAd.headline = "Luxury Cruise to Mars";
        textAd.description1 = "Visit the Red Planet in style.";
        textAd.description2 = "Low-gravity fun for everyone!";
        textAd.displayUrl = "www.example.com";
        textAd.destinationUrl = "http://www.example.com";

        // Check new ad for policy violations before adding it.
        String[] languageTarget = { "en" };
        GeoTarget geoTarget = new GeoTarget();
        CountryTargets countryTargets = new CountryTargets();
        countryTargets.countries = new String[] { "US" };
        geoTarget.countryTargets = countryTargets;
        ApiError[] errors = service.checkAds(
            new Ad[] { textAd }, languageTarget, geoTarget);

        // Add text ad if there are no policy violations.
        if (errors == null) {
          Ad[] ads = service.addAds(new Ad[] { textAd });

Code sample not available.
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Find similar businesses in Local Business Center.
my $business_name = SOAP::Data->name('name' => 'Domino\'s Pizza');
my $business_address = SOAP::Data->name('address' =>
  '89 Charlwood St, London, SW1V 4PB');
my $business_country_code = SOAP::Data->name('countryCode' => 'GB');
my $in_local_business_center = 0;

# Get business from Local Business Center or find similar business.
my @businesses;
my $response;
if ($in_local_business_center == 1) {
  $response = $service->call('getMyBusinesses', @headers);
  @businesses = ($response->result(), $response->paramsout());
}
else {
  $response = $service->call('findBusinesses' => $business_name,
    $business_address, $business_country_code, @headers);
  @businesses = ($response->result(), $response->paramsout());
}

# Get business key.
my $business_key;
foreach my $business (@businesses) {
  my $name = $business->{'name'};
  my $address = $business->{'address'};
  my $country_code = $business->{'countryCode'};

  if (index($business_name->value(), $name) > -1 or
      index($business_address->value(), $address) > -1 or
      index($business_country_code->value(), $country_code) > -1) {
    $business_key = $business->{'key'};
  }
}

# Create new local business ad structure.
if ($business_key) {
  my $ad_group_id = 'INSERT_AD_GROUP_ID_HERE';
  open(IMAGE, 'INSERT_BUSINESS_IMAGE_PATH_HERE');
  my $image_encoded = MIME::Base64::encode_base64(join('', <IMAGE>));
  open(ICON, 'INSERT_CUSTOM_ICON_PATH_HERE');
  my $icon_encoded = MIME::Base64::encode_base64(join('', <ICON>));
  my $local_business_ad = {
    'adGroupId' => $ad_group_id,
    'adType' => 'LocalBusinessAd',
    'businessImage' => {'data' => $image_encoded},
    'businessKey' => $business_key,
    'countryCode' => 'GB',
    'customIcon' => {'data' => $icon_encoded},
    'description1' => 'Choose from our delicious range now',
    'description2' => 'Pre-order or delivered to your door',
    'destinationUrl' => 'http://www.dominos.co.uk/',
    'displayUrl' => 'www.dominos.co.uk'
  };

  # Check new ad for policy violations before adding it.
  my $ads = SOAP::Data->name('ads' => [$local_business_ad]);
  my $language_target = SOAP::Data->name('languageTarget' => {
    'languages' => ['en']});
  my $geo_target = SOAP::Data->name('geoTarget' => {'countryTargets' => {
    'countries' => ['GB']}});
  my $response = $service->call('checkAds' => $ads, $language_target,
                                $geo_target, @headers);
  my @errors = ($response->result(), $response->paramsout());

  # Add local business ad if there are no policy violations.
  unless (@errors) {
    $response = $service->call('addAds' => $ads, @headers);
    my @ads = ($response->result(), $response->paramsout());

Code sample not available.
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Create new text ad structure.
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'
text_ad = {
  'adGroupId': SOAPpy.Types.untypedType(ad_group_id),
  'adType': SOAPpy.Types.untypedType('TextAd'),
  'headline': 'Luxury Cruise to Mars',
  'description1': 'Visit the Red Planet in style.',
  'description2': 'Low-gravity fun for everyone!',
  'displayUrl': 'www.example.com',
  'destinationUrl': 'http://www.example.com'
}

# Check new ad for policy violations before adding it.
language_target = {'languages': ['en']}
geo_target = {'countryTargets': {'countries': ['US']}}
errors = ad_service.checkAds([text_ad], language_target, geo_target)

# Convert to a list if we get back a single object.
if len(errors) > 0 and not isinstance(errors, list):
  errors = [errors]

# Add text ad if there are no policy violations.
if len(errors) == 0:
  ads = ad_service.addAds([text_ad])

Code sample not available.
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Create new text ad structure.
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
text_ad = %{
<ads>
  <adGroupId>#{ad_group_id}</adGroupId>
  <adType>TextAd</adType>
  <headline>Luxury Cruise to Mars</headline>
  <description1>Visit the Red Planet in style.</description1>
  <description2>Low-gravity fun for everyone!</description2>
  <displayUrl>www.example.com</displayUrl>
  <destinationUrl>http://www.example.com</destinationUrl>
</ads>
}

# Check new ad for policy violations before adding it
language_target = '<languageTarget><languages>en</languages></languageTarget>'
geo_target = %{
<geoTarget>
  <countryTargets>
    <countries>US</countries>
  </countryTargets>
</geoTarget>
}
errors = ad_service.checkAds(REXML::Document.new(
  "<checkAds>#{text_ad}#{language_target}#{geo_target}</checkAds>"))
if errors.respond_to?('checkAdsReturn')
  errors = errors.checkAdsReturn

  # Convert to a list if we get back a single object.
  if ! errors.respond_to?('each')
    errors = [errors]
  end
end

# Add text ad if there were no policy violations.
if errors.empty?
  ads = ad_service.addAds(REXML::Document.new(
    "<addAds>#{text_ad}</addAds>")).addAdsReturn

Code sample not available.
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Create new text ad structure.
$ad_group_id = 'INSERT_AD_GROUP_ID_HERE';
$text_ad =
  '<adGroupId>' . $ad_group_id . '</adGroupId>' .
  '<adType>TextAd</adType>' .
  '<headline>Luxury Cruise to Mars</headline>' .
  '<description1>Visit the Red Planet in style.</description1>' .
  '<description2>Low-gravity fun for everyone!</description2>' .
  '<displayUrl>www.example.com</displayUrl>' .
  '<destinationUrl>http://www.example.com</destinationUrl>';

# Check new ad for policy violations before adding it.
$language_target =
  '<languageTarget><languages>en</languages></languageTarget>';
$geo_target =
  '<geoTarget>' .
  '<countryTargets><countries>US</countries></countryTargets>' .
  '</geoTarget>';
$request_xml =
  '<checkAds>' .
  '<ads>' . $text_ad . '</ads>' . $language_target . $geo_target .
  '</checkAds>';
$errors = $ad_service->call('checkAds', $request_xml);
$errors = $errors['checkAdsReturn'];
if ($debug) show_xml($ad_service);
if ($ad_service->fault) show_fault($ad_service);

# Add text ad if there are no policy violations.
if (!$errors) {
  $request_xml =
    '<addAds>' .
    '<ads>' . $text_ad . '</ads>' .
    '</addAds>';
  $ads = $ad_service->call('addAds', $request_xml);
  $ads = $ads['addAdsReturn'];

Code sample not available.
12
13
14
15
16
17
18
19
20
21
22
23
    <!-- Creates a new text ad given an existing ad group. -->
    <addAds>
      <ads>
        <adGroupId>INSERT_AD_GROUP_ID_HERE</adGroupId>
        <adType>TextAd</adType>
        <headline>Luxury Cruise to Mars</headline>
        <description1>Visit the Red Planet in style.</description1>
        <description2>Low-gravity fun for everyone!</description2>
        <displayUrl>www.example.com</displayUrl>
        <destinationUrl>http://www.example.com</destinationUrl>
      </ads>
    </addAds>

Select a programming language to view its sample

checkAds

Check a batch of Ads for policy errors. The number of Ads in the batch is limited to the maximum number of Ads per adgroup.

Parameters

ads Ad[]
The Ads to be checked.

Ad is one of:

languageTarget LanguageTarget
The overriding language context
geoTarget GeoTarget
The overriding geographical context If the adGroupId is not specified for an Ad, at least one of languageTarget and geoTarget must be provided for policy checking to be possible. These fields will not be taken into consideration for policy checking:
  • id
  • disapproved
  • status

Response

ApiError[] A list of policy errors

Samples

Code sample not available.
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
      // Create new text ad structure.
      long adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");

      TextAd textAd = new TextAd();
      textAd.setAdGroupId(adGroupId);
      textAd.setAdType(AdType.TextAd);
      textAd.setHeadline("Luxury Cruise to Mars");
      textAd.setDescription1("Visit the Red Planet in style.");
      textAd.setDescription2("Low-gravity fun for everyone!");
      textAd.setDisplayUrl("www.example.com");
      textAd.setDestinationUrl("http://www.example.com");

      // Check new ad for policy violations before adding it.
      String[] languageTarget = new String[] {"en"};
      GeoTarget geoTarget = new GeoTarget();
      geoTarget.setCountryTargets(new CountryTargets(new String[] {"US"},
          new String[] {}));
      ApiError[] errors =
        service.checkAds(new Ad[] {textAd}, languageTarget, geoTarget);

      // Add text ad if there are no policy violations.
      if (errors == null) {
        Ad[] ads = service.addAds(new Ad[] {textAd});

Code sample not available.
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
        // Create new text ad structure.
        long adGroupId = long.Parse("INSERT_AD_GROUP_ID_HERE");

        TextAd textAd = new TextAd();
        textAd.adGroupId = adGroupId;
        textAd.adType = AdType.TextAd;
        textAd.adTypeSpecified = true;
        textAd.headline = "Luxury Cruise to Mars";
        textAd.description1 = "Visit the Red Planet in style.";
        textAd.description2 = "Low-gravity fun for everyone!";
        textAd.displayUrl = "www.example.com";
        textAd.destinationUrl = "http://www.example.com";

        // Check new ad for policy violations before adding it.
        String[] languageTarget = { "en" };
        GeoTarget geoTarget = new GeoTarget();
        CountryTargets countryTargets = new CountryTargets();
        countryTargets.countries = new String[] { "US" };
        geoTarget.countryTargets = countryTargets;
        ApiError[] errors = service.checkAds(
            new Ad[] { textAd }, languageTarget, geoTarget);

        // Add text ad if there are no policy violations.
        if (errors == null) {
          Ad[] ads = service.addAds(new Ad[] { textAd });

Code sample not available.
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Find similar businesses in Local Business Center.
my $business_name = SOAP::Data->name('name' => 'Domino\'s Pizza');
my $business_address = SOAP::Data->name('address' =>
  '89 Charlwood St, London, SW1V 4PB');
my $business_country_code = SOAP::Data->name('countryCode' => 'GB');
my $in_local_business_center = 0;

# Get business from Local Business Center or find similar business.
my @businesses;
my $response;
if ($in_local_business_center == 1) {
  $response = $service->call('getMyBusinesses', @headers);
  @businesses = ($response->result(), $response->paramsout());
}
else {
  $response = $service->call('findBusinesses' => $business_name,
    $business_address, $business_country_code, @headers);
  @businesses = ($response->result(), $response->paramsout());
}

# Get business key.
my $business_key;
foreach my $business (@businesses) {
  my $name = $business->{'name'};
  my $address = $business->{'address'};
  my $country_code = $business->{'countryCode'};

  if (index($business_name->value(), $name) > -1 or
      index($business_address->value(), $address) > -1 or
      index($business_country_code->value(), $country_code) > -1) {
    $business_key = $business->{'key'};
  }
}

# Create new local business ad structure.
if ($business_key) {
  my $ad_group_id = 'INSERT_AD_GROUP_ID_HERE';
  open(IMAGE, 'INSERT_BUSINESS_IMAGE_PATH_HERE');
  my $image_encoded = MIME::Base64::encode_base64(join('', <IMAGE>));
  open(ICON, 'INSERT_CUSTOM_ICON_PATH_HERE');
  my $icon_encoded = MIME::Base64::encode_base64(join('', <ICON>));
  my $local_business_ad = {
    'adGroupId' => $ad_group_id,
    'adType' => 'LocalBusinessAd',
    'businessImage' => {'data' => $image_encoded},
    'businessKey' => $business_key,
    'countryCode' => 'GB',
    'customIcon' => {'data' => $icon_encoded},
    'description1' => 'Choose from our delicious range now',
    'description2' => 'Pre-order or delivered to your door',
    'destinationUrl' => 'http://www.dominos.co.uk/',
    'displayUrl' => 'www.dominos.co.uk'
  };

  # Check new ad for policy violations before adding it.
  my $ads = SOAP::Data->name('ads' => [$local_business_ad]);
  my $language_target = SOAP::Data->name('languageTarget' => {
    'languages' => ['en']});
  my $geo_target = SOAP::Data->name('geoTarget' => {'countryTargets' => {
    'countries' => ['GB']}});
  my $response = $service->call('checkAds' => $ads, $language_target,
                                $geo_target, @headers);
  my @errors = ($response->result(), $response->paramsout());

  # Add local business ad if there are no policy violations.
  unless (@errors) {
    $response = $service->call('addAds' => $ads, @headers);
    my @ads = ($response->result(), $response->paramsout());

Code sample not available.
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Create new text ad structure.
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'
text_ad = {
  'adGroupId': SOAPpy.Types.untypedType(ad_group_id),
  'adType': SOAPpy.Types.untypedType('TextAd'),
  'headline': 'Luxury Cruise to Mars',
  'description1': 'Visit the Red Planet in style.',
  'description2': 'Low-gravity fun for everyone!',
  'displayUrl': 'www.example.com',
  'destinationUrl': 'http://www.example.com'
}

# Check new ad for policy violations before adding it.
language_target = {'languages': ['en']}
geo_target = {'countryTargets': {'countries': ['US']}}
errors = ad_service.checkAds([text_ad], language_target, geo_target)

# Convert to a list if we get back a single object.
if len(errors) > 0 and not isinstance(errors, list):
  errors = [errors]

# Add text ad if there are no policy violations.
if len(errors) == 0:
  ads = ad_service.addAds([text_ad])

Code sample not available.
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Create new text ad structure.
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
text_ad = %{
<ads>
  <adGroupId>#{ad_group_id}</adGroupId>
  <adType>TextAd</adType>
  <headline>Luxury Cruise to Mars</headline>
  <description1>Visit the Red Planet in style.</description1>
  <description2>Low-gravity fun for everyone!</description2>
  <displayUrl>www.example.com</displayUrl>
  <destinationUrl>http://www.example.com</destinationUrl>
</ads>
}

# Check new ad for policy violations before adding it
language_target = '<languageTarget><languages>en</languages></languageTarget>'
geo_target = %{
<geoTarget>
  <countryTargets>
    <countries>US</countries>
  </countryTargets>
</geoTarget>
}
errors = ad_service.checkAds(REXML::Document.new(
  "<checkAds>#{text_ad}#{language_target}#{geo_target}</checkAds>"))
if errors.respond_to?('checkAdsReturn')
  errors = errors.checkAdsReturn

  # Convert to a list if we get back a single object.
  if ! errors.respond_to?('each')
    errors = [errors]
  end
end

# Add text ad if there were no policy violations.
if errors.empty?
  ads = ad_service.addAds(REXML::Document.new(
    "<addAds>#{text_ad}</addAds>")).addAdsReturn

Code sample not available.
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Create new text ad structure.
$ad_group_id = 'INSERT_AD_GROUP_ID_HERE';
$text_ad =
  '<adGroupId>' . $ad_group_id . '</adGroupId>' .
  '<adType>TextAd</adType>' .
  '<headline>Luxury Cruise to Mars</headline>' .
  '<description1>Visit the Red Planet in style.</description1>' .
  '<description2>Low-gravity fun for everyone!</description2>' .
  '<displayUrl>www.example.com</displayUrl>' .
  '<destinationUrl>http://www.example.com</destinationUrl>';

# Check new ad for policy violations before adding it.
$language_target =
  '<languageTarget><languages>en</languages></languageTarget>';
$geo_target =
  '<geoTarget>' .
  '<countryTargets><countries>US</countries></countryTargets>' .
  '</geoTarget>';
$request_xml =
  '<checkAds>' .
  '<ads>' . $text_ad . '</ads>' . $language_target . $geo_target .
  '</checkAds>';
$errors = $ad_service->call('checkAds', $request_xml);
$errors = $errors['checkAdsReturn'];
if ($debug) show_xml($ad_service);
if ($ad_service->fault) show_fault($ad_service);

# Add text ad if there are no policy violations.
if (!$errors) {
  $request_xml =
    '<addAds>' .
    '<ads>' . $text_ad . '</ads>' .
    '</addAds>';
  $ads = $ad_service->call('addAds', $request_xml);
  $ads = $ads['addAdsReturn'];

Code sample not available.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    <!-- Checks ads for policy violations. Useful before calling addAds. -->
    <checkAds>
      <ads>
        <adType>ImageAd</adType>
        <displayUrl>www.example.com</displayUrl>
        <destinationUrl>http://www.example.com</destinationUrl>
        <image>
          <data>BASE64_ENCODED_DATA</data>
          <name>image_ad</name>
        </image>
      </ads>
      <languageTarget>
        <languages>en</languages>
      </languageTarget>
      <geoTarget>
        <countryTargets>
          <countries>US</countries>
        </countryTargets>
      </geoTarget>
    </checkAds>

Select a programming language to view its sample

findBusinesses

Searches for businesses with similar attributes. This call is similar to querying Google Local Search. All parameters are required.

Parameters

name string
Name of the business. Must not be null.
address string
Location of the business. Format is free form. Examples: "Mountain View, CA" or "1600 Amphitheatre Pkwy, Mountain View, CA". Must not be null.
countryCode string
Two letter country code of the business address. Must not be null.

Response

Business[] matching businesses

Samples

Code sample not available.
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
      // Find similar businesses in Local Business Center.
      String businessName = "Domino's Pizza";
      String businessAddress = "89 Charlwood St, London, SW1V 4PB";
      String businessCountryCode = "GB";
      boolean inLocalBusinessCenter = true;

      // Get business from Local Business Center or find similar business.
      Business[] businesses = {};
      if (inLocalBusinessCenter) {
        businesses = service.getMyBusinesses();
      } else {
        businesses = service.findBusinesses(
            businessName, businessAddress, businessCountryCode);
      }

      // Get business key.
      String businessKey = null;
      for (Business business : businesses) {
        String name = business.getName();
        String address = business.getAddress();
        String countryCode = business.getCountryCode();

        if (businessName.indexOf(name) >= 0 ||
            businessAddress.indexOf(address) >= 0 ||
            businessCountryCode.indexOf(countryCode) >= 0) {
          businessKey = business.getKey();
        }
      }

      // Create new local business ad structure.
      if (businessKey != null) {
        long adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");

        File lbaImageFile = new File("INSERT_BUSINESS_IMAGE_PATH_HERE");
        byte[] lbaImageData = new byte[(int)lbaImageFile.length()];
        BufferedInputStream imageInputStream =
            new BufferedInputStream(new FileInputStream(lbaImageFile));
        imageInputStream.read(lbaImageData);
        Image businessImage = new Image();
        businessImage.setData(lbaImageData);

        File lbaIconFile = new File("INSERT_CUSTOM_ICON_PATH_HERE");
        byte[] lbaIconData = new byte[(int)lbaIconFile.length()];
        BufferedInputStream iconInputStream =
            new BufferedInputStream(new FileInputStream(lbaIconFile));
        iconInputStream.read(lbaIconData);
        Image customIcon = new Image();
        customIcon.setData(lbaIconData);

        LocalBusinessAd localBusinessAd = new LocalBusinessAd();
        localBusinessAd.setAdGroupId(adGroupId);
        localBusinessAd.setAdType(AdType.LocalBusinessAd);
        localBusinessAd.setBusinessImage(businessImage);
        localBusinessAd.setBusinessKey(businessKey);
        localBusinessAd.setCustomIcon(customIcon);
        localBusinessAd.setDescription1("Choose from our delicious range now");
        localBusinessAd.setDescription2("Pre-order or delivered to your door");
        localBusinessAd.setDestinationUrl("http://www.dominos.co.uk/");
        localBusinessAd.setDisplayUrl("www.dominos.co.uk");
        localBusinessAd.setCountryCode("GB");

        // Check new ad for policy violations before adding it.
        String[] languageTarget = new String[] {"en"};
        GeoTarget geoTarget = new GeoTarget();
        geoTarget.setCountryTargets(new CountryTargets(new String[] {"GB"},
            new String[]{}));
        ApiError[] errors = service.checkAds(
            new Ad[] {localBusinessAd}, languageTarget, geoTarget);

        // Add local business ad if there are no policy violations.
        if (errors == null) {
          Ad[] ads = service.addAds(new Ad[] {localBusinessAd});

Code sample not available.
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
        // Find similar businesses in Local Business Center.
        String businessName = "Domino's Pizza";
        String businessAddress = "89 Charlwood St, London, SW1V 4PB";
        String businessCountryCode = "GB";
        int inLocalBusinessCenter = 0;

        // Get business from Local Business Center or find similar business.
        Business[] businesses = { };
        if (inLocalBusinessCenter == 1) {
          businesses = service.getMyBusinesses();
        } else {
          businesses = service.findBusinesses(
              businessName, businessAddress, businessCountryCode);
        }

        // Get business key.
        String businessKey = null;
        for (int i = 0; i < businesses.Length; i++) {
          String name = businesses[i].name;
          String address = businesses[i].address;
          String countryCode = businesses[i].countryCode;

          if (businessName.IndexOf(name) > -1 ||
               businessAddress.IndexOf(address) > -1 ||
               businessCountryCode.IndexOf(countryCode) > -1) {
            businessKey = businesses[i].key;
          }
        }

        // Create new local business ad structure.
        if (businessKey != null) {
          long adGroupId = long.Parse("INSERT_AD_GROUP_ID_HERE");

          FileStream fs = File.OpenRead("INSERT_BUSINESS_IMAGE_PATH_HERE");
          byte[] localBusinessImageData = new byte[fs.Length];
          fs.Read(localBusinessImageData, 0, localBusinessImageData.Length);
          fs.Close();

          fs = File.OpenRead("INSERT_CUSTOM_ICON_PATH_HERE");
          byte[] localBusinessIconData = new byte[fs.Length];
          fs.Read(localBusinessIconData, 0, localBusinessIconData.Length);
          fs.Close();

          LocalBusinessAd localBusinessAd = new LocalBusinessAd();
          localBusinessAd.adGroupId = adGroupId;
          localBusinessAd.adType = AdType.LocalBusinessAd;
          localBusinessAd.adTypeSpecified = true;

          SampleCode.com.google.sandbox.v13.AdService.Image businessImage =
              new SampleCode.com.google.sandbox.v13.AdService.Image();
          businessImage.data = localBusinessImageData;
          localBusinessAd.businessImage = businessImage;

          SampleCode.com.google.sandbox.v13.AdService.Image customImage =
              new SampleCode.com.google.sandbox.v13.AdService.Image();
          customImage.data = localBusinessIconData;
          localBusinessAd.customIcon = customImage;

          localBusinessAd.businessKey = businessKey;
          localBusinessAd.countryCode = "GB";
          localBusinessAd.description1 = "Choose from our delicious range now";
          localBusinessAd.description2 = "Pre-order or delivered to your door";
          localBusinessAd.destinationUrl = "http://www.dominos.co.uk";
          localBusinessAd.displayUrl = "www.dominos.co.uk";

          // Check new ad for policy violations before adding it.
          String[] languageTarget = { "en" };
          GeoTarget geoTarget = new GeoTarget();
          CountryTargets countryTargets = new CountryTargets();
          countryTargets.countries = new String[] { "US" };
          geoTarget.countryTargets = countryTargets;
          ApiError[] errors = service.checkAds(new Ad[] { localBusinessAd },
              languageTarget, geoTarget);

          // Add local business ad if there are no policy violations.
          if (errors == null) {
            Ad[] ads = service.addAds(new Ad[] { localBusinessAd });

Code sample not available.
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Find similar businesses in Local Business Center.
my $business_name = SOAP::Data->name('name' => 'Domino\'s Pizza');
my $business_address = SOAP::Data->name('address' =>
  '89 Charlwood St, London, SW1V 4PB');
my $business_country_code = SOAP::Data->name('countryCode' => 'GB');
my $in_local_business_center = 0;

# Get business from Local Business Center or find similar business.
my @businesses;
my $response;
if ($in_local_business_center == 1) {
  $response = $service->call('getMyBusinesses', @headers);
  @businesses = ($response->result(), $response->paramsout());
}
else {
  $response = $service->call('findBusinesses' => $business_name,
    $business_address, $business_country_code, @headers);
  @businesses = ($response->result(), $response->paramsout());
}

# Get business key.
my $business_key;
foreach my $business (@businesses) {
  my $name = $business->{'name'};
  my $address = $business->{'address'};
  my $country_code = $business->{'countryCode'};

  if (index($business_name->value(), $name) > -1 or
      index($business_address->value(), $address) > -1 or
      index($business_country_code->value(), $country_code) > -1) {
    $business_key = $business->{'key'};
  }
}

# Create new local business ad structure.
if ($business_key) {
  my $ad_group_id = 'INSERT_AD_GROUP_ID_HERE';
  open(IMAGE, 'INSERT_BUSINESS_IMAGE_PATH_HERE');
  my $image_encoded = MIME::Base64::encode_base64(join('', <IMAGE>));
  open(ICON, 'INSERT_CUSTOM_ICON_PATH_HERE');
  my $icon_encoded = MIME::Base64::encode_base64(join('', <ICON>));
  my $local_business_ad = {
    'adGroupId' => $ad_group_id,
    'adType' => 'LocalBusinessAd',
    'businessImage' => {'data' => $image_encoded},
    'businessKey' => $business_key,
    'countryCode' => 'GB',
    'customIcon' => {'data' => $icon_encoded},
    'description1' => 'Choose from our delicious range now',
    'description2' => 'Pre-order or delivered to your door',
    'destinationUrl' => 'http://www.dominos.co.uk/',
    'displayUrl' => 'www.dominos.co.uk'
  };

  # Check new ad for policy violations before adding it.
  my $ads = SOAP::Data->name('ads' => [$local_business_ad]);
  my $language_target = SOAP::Data->name('languageTarget' => {
    'languages' => ['en']});
  my $geo_target = SOAP::Data->name('geoTarget' => {'countryTargets' => {
    'countries' => ['GB']}});
  my $response = $service->call('checkAds' => $ads, $language_target,
                                $geo_target, @headers);
  my @errors = ($response->result(), $response->paramsout());

  # Add local business ad if there are no policy violations.
  unless (@errors) {
    $response = $service->call('addAds' => $ads, @headers);
    my @ads = ($response->result(), $response->paramsout());

Code sample not available.
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Find similar businesses in Local Business Center.
business_name = 'Domino\'s Pizza'
business_address = '89 Charlwood St, London, SW1V 4PB'
business_country_code = 'GB'
in_local_business_center = 0

# Get business from Local Business Center or find similar business.
if in_local_business_center == 1:
  businesses = ad_service.getMyBusinesses()
else:
  businesses = ad_service.findBusinesses(business_name,
                                         business_address,
                                         business_country_code)

# Convert to a list if we get back a single object.
if len(businesses) > 0 and not isinstance(businesses, list):
  businesses = [businesses]

# Get business key.
for business in businesses:
  name = business['name']
  address = business['address']
  country_code = business['countryCode']

  if (business_name.find(name) > -1 or business_address.find(address) > -1 or
      business_country_code.find(country_code) > -1):
    business_key = business['key']

# Create new local business ad structure.
if business_key != None:
  ad_group_id = 'INSERT_AD_GROUP_ID_HERE'
  business_image = open('INSERT_BUSINESS_IMAGE_PATH_HERE', 'r').read()
  custom_icon = open('INSERT_CUSTOM_ICON_PATH_HERE', 'r').read()
  local_business_ad = {
    'adGroupId': SOAPpy.Types.untypedType(ad_group_id),
    'adType': SOAPpy.Types.untypedType('LocalBusinessAd'),
    'businessImage':
      {'data': SOAPpy.Types.untypedType(base64.encodestring(business_image))},
    'businessKey': business_key,
    'countryCode': SOAPpy.Types.untypedType('GB'),
    'customIcon':
      {'data': SOAPpy.Types.untypedType(base64.encodestring(custom_icon))},
    'description1': 'Choose from our delicious range now',
    'description2': 'Pre-order or delivered to your door',
    'destinationUrl': 'http://www.dominos.co.uk/',
    'displayUrl': 'www.dominos.co.uk'
  }

  # Check new ad for policy violations before adding it.
  language_target = {'languages': ['en']}
  geo_target = {'countryTargets': {'countries': ['GB']}}
  errors = ad_service.checkAds([local_business_ad], language_target, geo_target)

  # Convert to a list if we get back a single object.
  if len(errors) > 0 and not isinstance(errors, list):
    errors = [errors]

  # Add local business ad if there are no policy violations.
  if len(errors) == 0:
    ads = ad_service.addAds([local_business_ad])

Code sample not available.
Code sample not available.
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Find similar businesses in Local Business Center.
$business_name = 'Domino\'s Pizza';
$business_address = '89 Charlwood St, London, SW1V 4PB';
$business_country_code = 'GB';
$in_local_business_center = 0;

# Get business from Local Business Center or find similar business.
$businesses = array();
if ($in_local_business_center) {
  $request_xml = '<getMyBusinesses></getMyBusinesses>';
  $businesses = $ad_service->call('getMyBusinesses', $request_xml);
  $businesses = $errors['getMyBusinessesReturn'];
  if ($debug) show_xml($ad_service);
  if ($ad_service->fault) show_fault($ad_service);

  # Convert to a list if we get back a single object.
  if (!$businesses[0]) {
    $businesses = array($businesses);
  }
} else {
  $request_xml =
    '<findBusinesses>' .
    '<name>' . $business_name . '</name>' .
    '<address>' . $business_address . '</address>' .
    '<countryCode>' . $business_country_code . '</countryCode>' .
    '</findBusinesses>';
  $businesses = $ad_service->call('findBusinesses', $request_xml);
  $businesses = $errors['findBusinessesReturn'];
  if ($debug) show_xml($ad_service);
  if ($ad_service->fault) show_fault($ad_service);

  # Convert to a list if we get back a single object.
  if (!$businesses[0]) {
    $businesses = array($businesses);
  }
}

# Get business key.
$business_key = '';
for ($i = 0; $i < count($businesses); $i++) {
  $name = $businesses[$i]['name'];
  $address = $businesses[$i]['address'];
  $country_code = $businesses[$i]['countryCode'];

  if ($business_name.strpos($name) != FALSE or
      $business_address.strpos($address) != FALSE or
      $business_country_code.strpos($country_code) != FALSE) {
    $business_key = $businesses[$i]['key'];
  }
}

# Create new local business ad structure.
if ($business_key != '') {
  $ad_group_id = 'INSERT_AD_GROUP_ID_HERE';
  $business_image = file_get_contents('INSERT_BUSINESS_IMAGE_PATH_HERE');
  $custom_icon = file_get_contents('INSERT_CUSTOM_ICON_PATH_HERE');

  $local_business_ad =
    '<adGroupId>' . $ad_group_id . '</adGroupId>' .
    '<adType>LocalBusinessAd</adType>' .
    '<businessImage>' .
    '<data>' . base64_encode($business_image) . '</data>' .
    '</businessImage>' .
    '<businessKey>' . $business_key . '</businessKey>' .
    '<customIcon>' .
    '<data>' . base64_encode($custom_icon) . '</data>' .
    '</customIcon>' .
    '<description1>Choose from our delicious range now</description1>' .
    '<description2>Pre-order or delivered to your door</description2>' .
    '<destinationUrl>http://www.dominos.co.uk/</destinationUrl>' .
    '<displayUrl>www.dominos.co.uk</displayUrl>';

    # Check new ad for policy violations before adding it.
    $language_target =
      '<languageTarget><languages>en</languages></languageTarget>';
    $geo_target =
      '<geoTarget>' .
      '<countryTargets><countries>US</countries></countryTargets>' .
      '</geoTarget>';
    $request_xml =
      '<checkAds>' .
      '<ads>' . $local_business_ad . '</ads>' . $language_target . $geo_target .
      '</checkAds>';
    $errors = $ad_service->call('checkAds', $request_xml);
    $errors = $errors['checkAdsReturn'];
    if ($debug) show_xml($ad_service);
    if ($ad_service->fault) show_fault($ad_service);

    # Add local business ad if there are no policy violations.
    if (!$errors) {
      $ads = $ad_service->call('addAds', $request_xml);
      $ads = $ads['addAdsReturn'];

Code sample not available.
12
13
14
15
16
17
    <!-- Finds businesses in the local business center. -->
    <findBusinesses>
      <name>Domino's Pizza</name>
      <address>89 Charlwood St, London, SW1V 4PB</address>
      <countryCode>GB</countryCode>
    </findBusinesses>

Select a programming language to view its sample

getActiveAds

Return all active Ads associated with the list of AdGroup ids specified.

Parameters

adGroupIds long[]
An array of AdGroup Ids that own the Ads

Response

Ad[] An array of the Ads

Ad is one of:

getAd

Return information about one Ad.

Parameters

adGroupId long
The ID of the AdGroup owning the Ad

For v11 and older, the type is int.

adId long
The ID of the Ad

Response

Ad The Ad

Ad is one of:

getAdStats

Get statistics for a list of ads in an ad group. See StatsRecord for details about the statistics returned. The time granularity is one day.

Parameters

adGroupId long
The ad group that contains the ads to be queried

For v11 and older, the type is int.

adIds long[]
The ads to query
startDay date
The starting day of the period for which statistics are to be collected (xsd:date).
endDay date
The ending day of the period for which statistics are to be collected, inclusive (xsd:date).

Response

StatsRecord[] an array of StatsRecords containing information about the activity on the ad. Note that the AveragePosition field is not used. The order of StatsRecord objects returned may be different from the order in which the id's were requested.

getAllAds

Return all Ads (enabled, disabled, or paused) associated with the list of AdGroup ids specified.

Parameters

adGroupIds long[]
An array of AdGroup IDs that own the Ads

For v11 and older, the type is int[].

Response

Ad[] An array of the Ads

Ad is one of:

Samples

Code sample not available.
57
58
59
      // Get all ads.
      long[] adGroupIds = {Long.parseLong("INSERT_AD_GROUP_ID_HERE")};
      Ad[] ads = service.getAllAds(adGroupIds);

Code sample not available.
55
56
57
        // Get all ads.
        long[] adGroupIds = { long.Parse("INSERT_AD_GROUP_ID_HERE") };
        Ad[] ads = service.getAllAds(adGroupIds);

Code sample not available.
60
61
62
63
64
# Get all ads.
my $ad_group_ids = SOAP::Data->name('adGroupIds' =>
  ['INSERT_AD_GROUP_ID_HERE']);
my $response = $service->call('getAllAds' => $ad_group_ids, @headers);
my @ads = ($response->result(), $response->paramsout());

Code sample not available.
48
49
50
# Get all ads.
ad_group_ids = [long('INSERT_AD_GROUP_ID_HERE')]
ads = ad_service.getAllAds(ad_group_ids)

Code sample not available.
63
64
65
# Get all ads.
ad_group_ids = ['INSERT_AD_GROUP_ID_HERE'.to_i]
ads = ad_service.getAllAds(ad_group_ids).getAllAdsReturn

Code sample not available.
49
50
51
52
53
54
55
56
# Get all ads.
$ad_group_id = 'INSERT_AD_GROUP_ID_HERE';
$request_xml =
  '<getAllAds>' .
  '<adGroupIds>' . $ad_group_id . '</adGroupIds>' .
  '</getAllAds>';
$ads = $ad_service->call('getAllAds', $request_xml);
$ads = $ads['getAllAdsReturn'];

Code sample not available.
12
13
14
15
    <!-- Retrieves all ads given an existing ad group. -->
    <getAllAds>
      <adGroupIds>INSERT_AD_GROUP_ID_HERE</adGroupIds>
    </getAllAds>

Select a programming language to view its sample

getMyBusinesses

Returns the list of businesses registered to the user in the Local Business Center. The user is determined by the clientEmail header if it is specified. Otherwise, the email header is used instead.

Response

Business[] the list of businesses registered to the user in the Local Business Center

Samples

Code sample not available.
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
      // Find similar businesses in Local Business Center.
      String businessName = "Domino's Pizza";
      String businessAddress = "89 Charlwood St, London, SW1V 4PB";
      String businessCountryCode = "GB";
      boolean inLocalBusinessCenter = true;

      // Get business from Local Business Center or find similar business.
      Business[] businesses = {};
      if (inLocalBusinessCenter) {
        businesses = service.getMyBusinesses();
      } else {
        businesses = service.findBusinesses(
            businessName, businessAddress, businessCountryCode);
      }

      // Get business key.
      String businessKey = null;
      for (Business business : businesses) {
        String name = business.getName();
        String address = business.getAddress();
        String countryCode = business.getCountryCode();

        if (businessName.indexOf(name) >= 0 ||
            businessAddress.indexOf(address) >= 0 ||
            businessCountryCode.indexOf(countryCode) >= 0) {
          businessKey = business.getKey();
        }
      }

      // Create new local business ad structure.
      if (businessKey != null) {
        long adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");

        File lbaImageFile = new File("INSERT_BUSINESS_IMAGE_PATH_HERE");
        byte[] lbaImageData = new byte[(int)lbaImageFile.length()];
        BufferedInputStream imageInputStream =
            new BufferedInputStream(new FileInputStream(lbaImageFile));
        imageInputStream.read(lbaImageData);
        Image businessImage = new Image();
        businessImage.setData(lbaImageData);

        File lbaIconFile = new File("INSERT_CUSTOM_ICON_PATH_HERE");
        byte[] lbaIconData = new byte[(int)lbaIconFile.length()];
        BufferedInputStream iconInputStream =
            new BufferedInputStream(new FileInputStream(lbaIconFile));
        iconInputStream.read(lbaIconData);
        Image customIcon = new Image();
        customIcon.setData(lbaIconData);

        LocalBusinessAd localBusinessAd = new LocalBusinessAd();
        localBusinessAd.setAdGroupId(adGroupId);
        localBusinessAd.setAdType(AdType.LocalBusinessAd);
        localBusinessAd.setBusinessImage(businessImage);
        localBusinessAd.setBusinessKey(businessKey);
        localBusinessAd.setCustomIcon(customIcon);
        localBusinessAd.setDescription1("Choose from our delicious range now");
        localBusinessAd.setDescription2("Pre-order or delivered to your door");
        localBusinessAd.setDestinationUrl("http://www.dominos.co.uk/");
        localBusinessAd.setDisplayUrl("www.dominos.co.uk");
        localBusinessAd.setCountryCode("GB");

        // Check new ad for policy violations before adding it.
        String[] languageTarget = new String[] {"en"};
        GeoTarget geoTarget = new GeoTarget();
        geoTarget.setCountryTargets(new CountryTargets(new String[] {"GB"},
            new String[]{}));
        ApiError[] errors = service.checkAds(
            new Ad[] {localBusinessAd}, languageTarget, geoTarget);

        // Add local business ad if there are no policy violations.
        if (errors == null) {
          Ad[] ads = service.addAds(new Ad[] {localBusinessAd});

Code sample not available.
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
        // Find similar businesses in Local Business Center.
        String businessName = "Domino's Pizza";
        String businessAddress = "89 Charlwood St, London, SW1V 4PB";
        String businessCountryCode = "GB";
        int inLocalBusinessCenter = 0;

        // Get business from Local Business Center or find similar business.
        Business[] businesses = { };
        if (inLocalBusinessCenter == 1) {
          businesses = service.getMyBusinesses();
        } else {
          businesses = service.findBusinesses(
              businessName, businessAddress, businessCountryCode);
        }

        // Get business key.
        String businessKey = null;
        for (int i = 0; i < businesses.Length; i++) {
          String name = businesses[i].name;
          String address = businesses[i].address;
          String countryCode = businesses[i].countryCode;

          if (businessName.IndexOf(name) > -1 ||
               businessAddress.IndexOf(address) > -1 ||
               businessCountryCode.IndexOf(countryCode) > -1) {
            businessKey = businesses[i].key;
          }
        }

        // Create new local business ad structure.
        if (businessKey != null) {
          long adGroupId = long.Parse("INSERT_AD_GROUP_ID_HERE");

          FileStream fs = File.OpenRead("INSERT_BUSINESS_IMAGE_PATH_HERE");
          byte[] localBusinessImageData = new byte[fs.Length];
          fs.Read(localBusinessImageData, 0, localBusinessImageData.Length);
          fs.Close();

          fs = File.OpenRead("INSERT_CUSTOM_ICON_PATH_HERE");
          byte[] localBusinessIconData = new byte[fs.Length];
          fs.Read(localBusinessIconData, 0, localBusinessIconData.Length);
          fs.Close();

          LocalBusinessAd localBusinessAd = new LocalBusinessAd();
          localBusinessAd.adGroupId = adGroupId;
          localBusinessAd.adType = AdType.LocalBusinessAd;
          localBusinessAd.adTypeSpecified = true;

          SampleCode.com.google.sandbox.v13.AdService.Image businessImage =
              new SampleCode.com.google.sandbox.v13.AdService.Image();
          businessImage.data = localBusinessImageData;
          localBusinessAd.businessImage = businessImage;

          SampleCode.com.google.sandbox.v13.AdService.Image customImage =
              new SampleCode.com.google.sandbox.v13.AdService.Image();
          customImage.data = localBusinessIconData;
          localBusinessAd.customIcon = customImage;

          localBusinessAd.businessKey = businessKey;
          localBusinessAd.countryCode = "GB";
          localBusinessAd.description1 = "Choose from our delicious range now";
          localBusinessAd.description2 = "Pre-order or delivered to your door";
          localBusinessAd.destinationUrl = "http://www.dominos.co.uk";
          localBusinessAd.displayUrl = "www.dominos.co.uk";

          // Check new ad for policy violations before adding it.
          String[] languageTarget = { "en" };
          GeoTarget geoTarget = new GeoTarget();
          CountryTargets countryTargets = new CountryTargets();
          countryTargets.countries = new String[] { "US" };
          geoTarget.countryTargets = countryTargets;
          ApiError[] errors = service.checkAds(new Ad[] { localBusinessAd },
              languageTarget, geoTarget);

          // Add local business ad if there are no policy violations.
          if (errors == null) {
            Ad[] ads = service.addAds(new Ad[] { localBusinessAd });

Code sample not available.
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Find similar businesses in Local Business Center.
my $business_name = SOAP::Data->name('name' => 'Domino\'s Pizza');
my $business_address = SOAP::Data->name('address' =>
  '89 Charlwood St, London, SW1V 4PB');
my $business_country_code = SOAP::Data->name('countryCode' => 'GB');
my $in_local_business_center = 0;

# Get business from Local Business Center or find similar business.
my @businesses;
my $response;
if ($in_local_business_center == 1) {
  $response = $service->call('getMyBusinesses', @headers);
  @businesses = ($response->result(), $response->paramsout());
}
else {
  $response = $service->call('findBusinesses' => $business_name,
    $business_address, $business_country_code, @headers);
  @businesses = ($response->result(), $response->paramsout());
}

# Get business key.
my $business_key;
foreach my $business (@businesses) {
  my $name = $business->{'name'};
  my $address = $business->{'address'};
  my $country_code = $business->{'countryCode'};

  if (index($business_name->value(), $name) > -1 or
      index($business_address->value(), $address) > -1 or
      index($business_country_code->value(), $country_code) > -1) {
    $business_key = $business->{'key'};
  }
}

# Create new local business ad structure.
if ($business_key) {
  my $ad_group_id = 'INSERT_AD_GROUP_ID_HERE';
  open(IMAGE, 'INSERT_BUSINESS_IMAGE_PATH_HERE');
  my $image_encoded = MIME::Base64::encode_base64(join('', <IMAGE>));
  open(ICON, 'INSERT_CUSTOM_ICON_PATH_HERE');
  my $icon_encoded = MIME::Base64::encode_base64(join('', <ICON>));
  my $local_business_ad = {
    'adGroupId' => $ad_group_id,
    'adType' => 'LocalBusinessAd',
    'businessImage' => {'data' => $image_encoded},
    'businessKey' => $business_key,
    'countryCode' => 'GB',
    'customIcon' => {'data' => $icon_encoded},
    'description1' => 'Choose from our delicious range now',
    'description2' => 'Pre-order or delivered to your door',
    'destinationUrl' => 'http://www.dominos.co.uk/',
    'displayUrl' => 'www.dominos.co.uk'
  };

  # Check new ad for policy violations before adding it.
  my $ads = SOAP::Data->name('ads' => [$local_business_ad]);
  my $language_target = SOAP::Data->name('languageTarget' => {
    'languages' => ['en']});
  my $geo_target = SOAP::Data->name('geoTarget' => {'countryTargets' => {
    'countries' => ['GB']}});
  my $response = $service->call('checkAds' => $ads, $language_target,
                                $geo_target, @headers);
  my @errors = ($response->result(), $response->paramsout());

  # Add local business ad if there are no policy violations.
  unless (@errors) {
    $response = $service->call('addAds' => $ads, @headers);
    my @ads = ($response->result(), $response->paramsout());

Code sample not available.
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Find similar businesses in Local Business Center.
business_name = 'Domino\'s Pizza'
business_address = '89 Charlwood St, London, SW1V 4PB'
business_country_code = 'GB'
in_local_business_center = 0

# Get business from Local Business Center or find similar business.
if in_local_business_center == 1:
  businesses = ad_service.getMyBusinesses()
else:
  businesses = ad_service.findBusinesses(business_name,
                                         business_address,
                                         business_country_code)

# Convert to a list if we get back a single object.
if len(businesses) > 0 and not isinstance(businesses, list):
  businesses = [businesses]

# Get business key.
for business in businesses:
  name = business['name']
  address = business['address']
  country_code = business['countryCode']

  if (business_name.find(name) > -1 or business_address.find(address) > -1 or
      business_country_code.find(country_code) > -1):
    business_key = business['key']

# Create new local business ad structure.
if business_key != None:
  ad_group_id = 'INSERT_AD_GROUP_ID_HERE'
  business_image = open('INSERT_BUSINESS_IMAGE_PATH_HERE', 'r').read()
  custom_icon = open('INSERT_CUSTOM_ICON_PATH_HERE', 'r').read()
  local_business_ad = {
    'adGroupId': SOAPpy.Types.untypedType(ad_group_id),
    'adType': SOAPpy.Types.untypedType('LocalBusinessAd'),
    'businessImage':
      {'data': SOAPpy.Types.untypedType(base64.encodestring(business_image))},
    'businessKey': business_key,
    'countryCode': SOAPpy.Types.untypedType('GB'),
    'customIcon':
      {'data': SOAPpy.Types.untypedType(base64.encodestring(custom_icon))},
    'description1': 'Choose from our delicious range now',
    'description2': 'Pre-order or delivered to your door',
    'destinationUrl': 'http://www.dominos.co.uk/',
    'displayUrl': 'www.dominos.co.uk'
  }

  # Check new ad for policy violations before adding it.
  language_target = {'languages': ['en']}
  geo_target = {'countryTargets': {'countries': ['GB']}}
  errors = ad_service.checkAds([local_business_ad], language_target, geo_target)

  # Convert to a list if we get back a single object.
  if len(errors) > 0 and not isinstance(errors, list):
    errors = [errors]

  # Add local business ad if there are no policy violations.
  if len(errors) == 0:
    ads = ad_service.addAds([local_business_ad])

Code sample not available.
Code sample not available.
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Find similar businesses in Local Business Center.
$business_name = 'Domino\'s Pizza';
$business_address = '89 Charlwood St, London, SW1V 4PB';
$business_country_code = 'GB';
$in_local_business_center = 0;

# Get business from Local Business Center or find similar business.
$businesses = array();
if ($in_local_business_center) {
  $request_xml = '<getMyBusinesses></getMyBusinesses>';
  $businesses = $ad_service->call('getMyBusinesses', $request_xml);
  $businesses = $errors['getMyBusinessesReturn'];
  if ($debug) show_xml($ad_service);
  if ($ad_service->fault) show_fault($ad_service);

  # Convert to a list if we get back a single object.
  if (!$businesses[0]) {
    $businesses = array($businesses);
  }
} else {
  $request_xml =
    '<findBusinesses>' .
    '<name>' . $business_name . '</name>' .
    '<address>' . $business_address . '</address>' .
    '<countryCode>' . $business_country_code . '</countryCode>' .
    '</findBusinesses>';
  $businesses = $ad_service->call('findBusinesses', $request_xml);
  $businesses = $errors['findBusinessesReturn'];
  if ($debug) show_xml($ad_service);
  if ($ad_service->fault) show_fault($ad_service);

  # Convert to a list if we get back a single object.
  if (!$businesses[0]) {
    $businesses = array($businesses);
  }
}

# Get business key.
$business_key = '';
for ($i = 0; $i < count($businesses); $i++) {
  $name = $businesses[$i]['name'];
  $address = $businesses[$i]['address'];
  $country_code = $businesses[$i]['countryCode'];

  if ($business_name.strpos($name) != FALSE or
      $business_address.strpos($address) != FALSE or
      $business_country_code.strpos($country_code) != FALSE) {
    $business_key = $businesses[$i]['key'];
  }
}

# Create new local business ad structure.
if ($business_key != '') {
  $ad_group_id = 'INSERT_AD_GROUP_ID_HERE';
  $business_image = file_get_contents('INSERT_BUSINESS_IMAGE_PATH_HERE');
  $custom_icon = file_get_contents('INSERT_CUSTOM_ICON_PATH_HERE');

  $local_business_ad =
    '<adGroupId>' . $ad_group_id . '</adGroupId>' .
    '<adType>LocalBusinessAd</adType>' .
    '<businessImage>' .
    '<data>' . base64_encode($business_image) . '</data>' .
    '</businessImage>' .
    '<businessKey>' . $business_key . '</businessKey>' .
    '<customIcon>' .
    '<data>' . base64_encode($custom_icon) . '</data>' .
    '</customIcon>' .
    '<description1>Choose from our delicious range now</description1>' .
    '<description2>Pre-order or delivered to your door</description2>' .
    '<destinationUrl>http://www.dominos.co.uk/</destinationUrl>' .
    '<displayUrl>www.dominos.co.uk</displayUrl>';

    # Check new ad for policy violations before adding it.
    $language_target =
      '<languageTarget><languages>en</languages></languageTarget>';
    $geo_target =
      '<geoTarget>' .
      '<countryTargets><countries>US</countries></countryTargets>' .
      '</geoTarget>';
    $request_xml =
      '<checkAds>' .
      '<ads>' . $local_business_ad . '</ads>' . $language_target . $geo_target .
      '</checkAds>';
    $errors = $ad_service->call('checkAds', $request_xml);
    $errors = $errors['checkAdsReturn'];
    if ($debug) show_xml($ad_service);
    if ($ad_service->fault) show_fault($ad_service);

    # Add local business ad if there are no policy violations.
    if (!$errors) {
      $ads = $ad_service->call('addAds', $request_xml);
      $ads = $ads['addAdsReturn'];

Code sample not available.
Select a programming language to view its sample

getMyVideos

Returns a list of all videos stored under the users account. The user is determined by the clientEmail if specified. Otherwise, the email header is used.

Response

Video[] the list of videos stored under user account.

updateAds

Update a batch of ads.

Use the id field of the ad to indicate which ad to update. Currently only the status field is updateable, all other fields will be ignored. You must specify the adGroupId element for each ads element.

Parameters

ads Ad[]
the Ads to be updated.

Ad is one of:

Response

(none)

Samples

Code sample not available.
60
61
62
63
64
65
66
67
68
69
70
      // Create existing ad structure.
      long adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");
      long adId = Long.parseLong("INSERT_AD_ID_HERE");
      TextAd textAd = new TextAd();
      textAd.setAdGroupId(adGroupId);
      textAd.setAdType(AdType.TextAd);
      textAd.setId(adId);
      textAd.setStatus(AdStatus.Disabled);

      // Delete ad.
      service.updateAds(new Ad[] {textAd});

Code sample not available.
55
56
57
58
59
60
61
62
63
64
65
66
67
68
        // Create existing ad structure.
        long adGroupId = long.Parse("INSERT_AD_GROUP_ID_HERE");
        long adId = long.Parse("INSERT_AD_ID_HERE");

        TextAd textAd = new TextAd();
        textAd.adGroupId = adGroupId;
        textAd.adType = AdType.TextAd;
        textAd.adTypeSpecified = true;
        textAd.id = adId;
        textAd.status = AdStatus.Disabled;
        textAd.statusSpecified = true;

        // Delete ad.
        service.updateAds(new Ad[] { textAd });

Code sample not available.
Code sample not available.
49
50
51
52
53
54
55
56
57
58
59
60
# Create existing ad structure.
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'
ad_id = 'INSERT_AD_ID_HERE'
ad = {
  'adGroupId': SOAPpy.Types.untypedType(ad_group_id),
  'adType': SOAPpy.Types.untypedType('TextAd'),
  'id': SOAPpy.Types.untypedType(ad_id),
  'status': SOAPpy.Types.untypedType('Disabled')
}

# Delete ad.
ad_service.updateAds([ad])

Code sample not available.
64
65
66
67
68
69
70
71
72
73
74
75
76
# Create existing ad structure.
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
ad_id = 'INSERT_AD_ID_HERE'.to_i
ad = {
  :adGroupId => ad_group_id,
  :adType => 'TextAd',
  :disapproved => SOAP::SOAPNil.new,
  :id => ad_id,
  :status => 'Disabled',
}

# Delete ad.
ad_service.updateAds([ad])

Code sample not available.
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Create existing ad structure.
$ad_group_id = 'INSERT_AD_GROUP_ID_HERE';
$ad_id = 'INSERT_AD_ID_HERE';
$ad =
  '<adGroupId>' . $ad_group_id . '</adGroupId>' .
  '<adType>TextAd</adType>' .
  '<id>' . $ad_id . '</id>' .
  '<status>Disabled</status>';

# Delete ad.
$request_xml =
  '<updateAds>' .
  '<ads>' . $ad . '</ads>' .
  '</updateAds>';
$ad_service->call('updateAds', $request_xml);

Code sample not available.
12
13
14
15
16
17
18
19
20
    <!-- Deletes an existing ad given an ad group. -->
    <updateAds>
      <ads>
        <adGroupId>INSERT_AD_GROUP_ID_HERE</adGroupId>
        <adType>TextAd</adType>
        <id>INSERT_AD_ID_HERE</id>
        <status>Disabled</status>
      </ads>
    </updateAds>

Select a programming language to view its sample