* @param campaignId the id of the campaign
* @return the id of the created ad extension
*/
public long createLocationExtension(long campaignId) throws Exception {
// Get the CampaignAdExtensionService.
CampaignAdExtensionServiceInterface campaignAdExtensionService =
user.getService(AdWordsService.V201008.CAMPAIGN_AD_EXTENSION_SERVICE);
// Get the GeoLocationService.
GeoLocationServiceInterface geoLocationService =
user.getService(AdWordsService.V201008.GEO_LOCATION_SERVICE);
// Create address.
Address address = new Address();
address.setStreetAddress("1600 Amphitheatre Parkway");
address.setCityName("Mountain View");
address.setProvinceCode("US-CA");
address.setPostalCode("94043");
address.setCountryCode("US");
// Create geo location selector.
GeoLocationSelector selector = new GeoLocationSelector();
selector.setAddresses(new Address[] {address});
// Get geo location.
GeoLocation[] geoLocationResult = geoLocationService.get(selector);
GeoLocation geoLocation = geoLocationResult[0];
// Create location extension.
LocationExtension locationExtension = new LocationExtension();
locationExtension.setAddress(geoLocation.getAddress());
locationExtension.setGeoPoint(geoLocation.getGeoPoint());
locationExtension.setEncodedLocation(geoLocation.getEncodedLocation());
locationExtension.setCompanyName("Google");
locationExtension.setPhoneNumber("650-253-0000");
locationExtension.setSource(LocationExtensionSource.ADWORDS_FRONTEND);
// Create campaign ad extension.
CampaignAdExtension campaignAdExtension = new CampaignAdExtension();
campaignAdExtension.setCampaignId(campaignId);
campaignAdExtension.setAdExtension(locationExtension);
// Create operations.
CampaignAdExtensionOperation operation = new CampaignAdExtensionOperation();
operation.setOperand(campaignAdExtension);
operation.setOperator(Operator.ADD);
CampaignAdExtensionOperation[] operations = new CampaignAdExtensionOperation[] {operation};
// Add campaign ad extension and retrun AdExtension ID.
return campaignAdExtensionService.mutate(operations).getValue()[0].getAdExtension().getId();
}