Ad Extensions in Java

 

The following example shows how to add extensions to an account’s ad extension library, get extensions from the library, associate the extensions with a campaign, get the extensions that are associated with a campaign, and determine why an extension failed editorial review using the following Campaign Management service operations.

This example has been developed and run within the environment described in Getting Started Using Java with Bing Ads Services. To get started developing Bing Ads applications with Java, Installing the SDK and either start with the provided examples or follow one of the application walkthroughs for a Web or Desktop application.

Note: This example uses the UserName and Password elements for authentication. For Managing User Authentication with OAuth, replace the UserName and Password elements with the AuthenticationToken, which is your OAuth access token.

package com.microsoft.bingads.examples.v10;

import java.rmi.*;
import java.util.ArrayList;

import com.microsoft.bingads.*;
import com.microsoft.bingads.v10.campaignmanagement.*;

public class AdExtensions {

    static AuthorizationData authorizationData;
    static ServiceClient<ICampaignManagementService> CampaignService; 

    protected static java.lang.String UserName = "<UserNameGoesHere>";
    protected static java.lang.String Password = "<PasswordGoesHere>";
    protected static java.lang.String DeveloperToken = "<DeveloperTokenGoesHere>";
    protected static long CustomerId = <CustomerIdGoesHere>;
    protected static long AccountId = <AccountIdGoesHere>;

    // Prints the string to System.out
    protected static void outputStatusMessage(java.lang.String message){
        System.out.println(message);
    }

    public static void main(java.lang.String[] args) {

        try
        {
             authorizationData = new AuthorizationData();
             authorizationData.setDeveloperToken(DeveloperToken);
             authorizationData.setAuthentication(new PasswordAuthentication(UserName, Password));
             authorizationData.setCustomerId(CustomerId);
             authorizationData.setAccountId(AccountId);

             CampaignService = new ServiceClient<ICampaignManagementService>(
                        authorizationData,
                        ICampaignManagementService.class);

             // Specify one or more campaigns.

             ArrayOfCampaign campaigns = new ArrayOfCampaign();
             Campaign campaign = new Campaign();
             campaign.setName("Summer Shoes " + System.currentTimeMillis());
             campaign.setDescription("Summer shoes line.");
             campaign.setBudgetType(BudgetLimitType.MONTHLY_BUDGET_SPEND_UNTIL_DEPLETED);
             campaign.setMonthlyBudget(1000.00);
             campaign.setTimeZone("PacificTimeUSCanadaTijuana");
             campaign.setDaylightSaving(true);

             // Used with FinalUrls shown in the sitelinks that we will add below.
             campaign.setTrackingUrlTemplate(
                     "http://tracker.example.com/?season={_season}&promocode={_promocode}&u={lpurl}");

             campaigns.getCampaigns().add(campaign);

             AddCampaignsResponse addCampaignsResponse = addCampaigns(AccountId, campaigns);
             ArrayOfNullableOflong campaignIds = addCampaignsResponse.getCampaignIds();
             ArrayOfBatchError campaignErrors = addCampaignsResponse.getPartialErrors();
             outputCampaignsWithPartialErrors(campaigns, campaignIds, campaignErrors);

             // Specify the extensions.

             ArrayOfAdExtension adExtensions = new ArrayOfAdExtension();

             AppAdExtension appAdExtension = new AppAdExtension();
             appAdExtension.setAppPlatform("Windows");
             appAdExtension.setAppStoreId("AppStoreIdGoesHere");
             appAdExtension.setDestinationUrl("DestinationUrlGoesHere");
             appAdExtension.setDisplayText("Contoso");
             adExtensions.getAdExtensions().add(appAdExtension);

             CallAdExtension callAdExtension = new CallAdExtension();
             callAdExtension.setCountryCode("US");
             callAdExtension.setPhoneNumber("2065550100");
             callAdExtension.setIsCallOnly(false);
             adExtensions.getAdExtensions().add(callAdExtension);

             LocationAdExtension locationAdExtension = new LocationAdExtension();
             locationAdExtension.setPhoneNumber("206-555-0100");
             locationAdExtension.setCompanyName("Contoso Shoes");
             locationAdExtension.setIconMediaId(null); 
             locationAdExtension.setImageMediaId(null);
             Address address = new Address();
             address.setStreetAddress("1234 Washington Place");
             address.setStreetAddress2("Suite 1210");
             address.setCityName("Woodinville");
             address.setProvinceName("WA"); 
             address.setCountryCode("US");
             address.setPostalCode("98608");
             locationAdExtension.setAddress(address);
             adExtensions.getAdExtensions().add(locationAdExtension);

             SiteLinksAdExtension siteLinksAdExtension = new SiteLinksAdExtension();
             ArrayOfSiteLink siteLinks = new ArrayOfSiteLink();

             for(int i=0; i < 2; i++){
                 SiteLink siteLink = new SiteLink();
                 siteLink.setDisplayText("Women's Shoe Sale " + (i+1));

                 // If you are currently using Destination URLs, you must replace them with Final URLs. 
                 // Here is an example of a DestinationUrl you might have used previously. 
                 // siteLink.setDestinationUrl("http://www.contoso.com/womenshoesale/?season=spring&promocode=PROMO123");

                 // To migrate from DestinationUrl to FinalUrls for existing sitelinks, you can set DestinationUrl
                 // to an empty string when updating the sitelink. If you are removing DestinationUrl,
                 // then FinalUrls is required.
                 // siteLink.setDestinationUrl("");

                 // With FinalUrls you can separate the tracking template, custom parameters, and 
                 // landing page URLs. 
                 ArrayOfstring finalUrls = new ArrayOfstring();
                 finalUrls.getStrings().add("http://www.contoso.com/womenshoesale");
                 siteLink.setFinalUrls(finalUrls);

                 // Final Mobile URLs can also be used if you want to direct the user to a different page 
                 // for mobile devices.
                 ArrayOfstring finalMobileUrls = new ArrayOfstring();
                 finalMobileUrls.getStrings().add("http://mobile.contoso.com/womenshoesale");
                 siteLink.setFinalMobileUrls(finalMobileUrls);

                 // You could use a tracking template which would override the campaign level
                 // tracking template. Tracking templates defined for lower level entities 
                 // override those set for higher level entities.
                 // In this example we are using the campaign level tracking template.
                 siteLink.setTrackingUrlTemplate(null);

                 // Set custom parameters that are specific to this sitelink, 
                 // and can be used by the sitelink, ad group, campaign, or account level tracking template. 
                 // In this example we are using the campaign level tracking template.
                 CustomParameters urlCustomParameters = new CustomParameters();
                 CustomParameter customParameter1 = new CustomParameter();
                 customParameter1.setKey("promoCode");
                 customParameter1.setValue("PROMO" + (i+1));
                 ArrayOfCustomParameter customParameters = new ArrayOfCustomParameter();
                 customParameters.getCustomParameters().add(customParameter1);
                 CustomParameter customParameter2 = new CustomParameter();
                 customParameter2.setKey("season");
                 customParameter2.setValue("summer");
                 customParameters.getCustomParameters().add(customParameter2);
                 urlCustomParameters.setParameters(customParameters);
                 siteLink.setUrlCustomParameters(urlCustomParameters);

                 siteLinks.getSiteLinks().add(siteLink);
             }

             siteLinksAdExtension.setSiteLinks(siteLinks);
             adExtensions.getAdExtensions().add(siteLinksAdExtension);

             // Add all extensions to the account's ad extension library
             ArrayOfAdExtensionIdentity adExtensionIdentities = addAdExtensions(
                 AccountId,
                 adExtensions
                 );

             outputStatusMessage("Added ad extensions.\n");

             // DeleteAdExtensionsAssociations, SetAdExtensionsAssociations, and GetAdExtensionsEditorialReasons 
             // operations each require a list of type AdExtensionIdToEntityIdAssociation.
             ArrayOfAdExtensionIdToEntityIdAssociation adExtensionIdToEntityIdAssociations = new ArrayOfAdExtensionIdToEntityIdAssociation();

             // GetAdExtensionsByIds requires a list of type long.
             ArrayOflong adExtensionIds = new ArrayOflong();

             // Loop through the list of extension IDs and build any required data structures
             // for subsequent operations. 

             for (AdExtensionIdentity adExtensionIdentity : adExtensionIdentities.getAdExtensionIdentities()) {
                 AdExtensionIdToEntityIdAssociation adExtensionIdToEntityIdAssociation = new AdExtensionIdToEntityIdAssociation();
                 adExtensionIdToEntityIdAssociation.setAdExtensionId(adExtensionIdentity.getId());
                 adExtensionIdToEntityIdAssociation.setEntityId(campaignIds.getLongs().get(0));
                 adExtensionIdToEntityIdAssociations.getAdExtensionIdToEntityIdAssociations().add(adExtensionIdToEntityIdAssociation);

                 adExtensionIds.getLongs().add(adExtensionIdentity.getId());
             }

             // Associate the specified ad extensions with the respective campaigns or ad groups. 
             setAdExtensionsAssociations(
                 AccountId, 
                 adExtensionIdToEntityIdAssociations, 
                 AssociationType.CAMPAIGN
                 );

             outputStatusMessage("Set ad extension associations.\n");

             // Get editorial rejection reasons for the respective ad extension and entity associations.
             ArrayOfAdExtensionEditorialReasonCollection adExtensionEditorialReasonCollection = getAdExtensionsEditorialReasons(
                 AccountId, 
                 adExtensionIdToEntityIdAssociations, 
                 AssociationType.CAMPAIGN
                 );

             ArrayList<AdExtensionsTypeFilter> adExtensionsTypeFilter = new ArrayList<AdExtensionsTypeFilter>();
             adExtensionsTypeFilter.add(AdExtensionsTypeFilter.APP_AD_EXTENSION);
             adExtensionsTypeFilter.add(AdExtensionsTypeFilter.CALL_AD_EXTENSION);
             adExtensionsTypeFilter.add(AdExtensionsTypeFilter.LOCATION_AD_EXTENSION);
             adExtensionsTypeFilter.add(AdExtensionsTypeFilter.SITE_LINKS_AD_EXTENSION);

             // Get the specified ad extensions from the account’s ad extension library.
             adExtensions = getAdExtensionsByIds(
                 AccountId,
                 adExtensionIds, 
                 adExtensionsTypeFilter
                 );

             int index = 0;                     

             for (AdExtension extension : adExtensions.getAdExtensions())
             {
                 if (extension == null || extension.getId() == null)
                 {
                     outputStatusMessage("Extension is null or invalid.");
                 }
                 else
                 {
                     if (extension instanceof AppAdExtension)
                     {
                         outputStatusMessage("AppAdExtension: ");
                         outputAppAdExtension((AppAdExtension)extension);
                     }
                     else if (extension instanceof CallAdExtension)
                     {
                         outputStatusMessage("CallAdExtension: ");
                         outputCallAdExtension((CallAdExtension)extension);
                     }
                     else if (extension instanceof LocationAdExtension)
                     {
                         outputStatusMessage("LocationAdExtension: ");
                         outputLocationAdExtension((LocationAdExtension)extension);
                     }
                     else if (extension instanceof SiteLinksAdExtension)
                     {
                         outputStatusMessage("SiteLinksAdExtension: ");
                         outputSiteLinksAdExtension((SiteLinksAdExtension)extension);
                     }
                     else
                     {
                         outputStatusMessage("Unknown extension type");
                     }

                     if (adExtensionEditorialReasonCollection != null 
                             && adExtensionEditorialReasonCollection.getAdExtensionEditorialReasonCollections().size() > 0
                             && adExtensionEditorialReasonCollection.getAdExtensionEditorialReasonCollections().get(index) != null)
                     {
                         outputStatusMessage("\n");

                         // Print any editorial rejection reasons for the corresponding extension. This sample 
                         // assumes the same list index for adExtensions and adExtensionEditorialReasonCollection
                         // as defined above.

                         for (AdExtensionEditorialReason adExtensionEditorialReason : 
                             adExtensionEditorialReasonCollection.getAdExtensionEditorialReasonCollections().get(index).getReasons().getAdExtensionEditorialReasons())
                         {
                             if (adExtensionEditorialReason != null &&
                                 adExtensionEditorialReason.getPublisherCountries() != null)
                             {
                                 outputStatusMessage("Editorial Rejection Location: " + adExtensionEditorialReason.getLocation());
                                 outputStatusMessage("Editorial Rejection PublisherCountries: ");
                                 for (java.lang.String publisherCountry : adExtensionEditorialReason.getPublisherCountries().getStrings())
                                 {
                                     outputStatusMessage("  " + publisherCountry);
                                 }
                                 outputStatusMessage("Editorial Rejection ReasonCode: " + adExtensionEditorialReason.getReasonCode());
                                 outputStatusMessage("Editorial Rejection Term: " + adExtensionEditorialReason.getTerm());
                                 outputStatusMessage("\n");
                             }
                         }
                     }
                 }

                 outputStatusMessage("");

                 index++;
             }

             // Remove the specified associations from the respective campaigns or ad groups. 
             // The extensions are still available in the account's extensions library. 
             deleteAdExtensionsAssociations(
                 AccountId,
                 adExtensionIdToEntityIdAssociations,
                 AssociationType.CAMPAIGN
                 );

             outputStatusMessage("Deleted ad extension associations.\n");

             // Deletes the ad extensions from the account’s ad extension library.
             deleteAdExtensions(
                 AccountId,
                 adExtensionIds
                 );

             outputStatusMessage("Deleted ad extensions.\n");

             // Delete the campaign from the account.

             ArrayOflong deleteCampaignIds = new ArrayOflong();
             deleteCampaignIds.getLongs().add(campaignIds.getLongs().get(0));
             deleteCampaigns(AccountId, deleteCampaignIds);
             outputStatusMessage(String.format("Deleted CampaignId %d\n", campaignIds.getLongs().get(0)));

         // Campaign Management service operations can throw AdApiFaultDetail.
         } catch (AdApiFaultDetail_Exception ex) {
             outputStatusMessage("The operation failed with the following faults:\n");

             for (AdApiError error : ex.getFaultInfo().getErrors().getAdApiErrors())
             {
                 outputStatusMessage("AdApiError\n");
                 outputStatusMessage(String.format("Code: %d\nError Code: %s\nMessage: %s\n\n", 
                         error.getCode(), error.getErrorCode(), error.getMessage()));
             }

         // Campaign Management service operations can throw ApiFaultDetail.
         } catch (ApiFaultDetail_Exception ex) {
             outputStatusMessage("The operation failed with the following faults:\n");

             for (BatchError error : ex.getFaultInfo().getBatchErrors().getBatchErrors())
             {
                 outputStatusMessage(String.format("BatchError at Index: %d\n", error.getIndex()));
                 outputStatusMessage(String.format("Code: %d\nMessage: %s\n\n", error.getCode(), error.getMessage()));
             }

             for (OperationError error : ex.getFaultInfo().getOperationErrors().getOperationErrors())
             {
                 outputStatusMessage("OperationError\n");
                 outputStatusMessage(String.format("Code: %d\nMessage: %s\n\n", error.getCode(), error.getMessage()));
             }

         // Some Campaign Management service operations such as SetAdExtensionsAssociations can throw EditorialApiFaultDetail.
         } catch (EditorialApiFaultDetail_Exception ex) {
             outputStatusMessage("The operation failed with the following faults:\n");

             for (BatchError error : ex.getFaultInfo().getBatchErrors().getBatchErrors())
             {
                 outputStatusMessage(String.format("BatchError at Index: %d\n", error.getIndex()));
                 outputStatusMessage(String.format("Code: %d\nMessage: %s\n\n", error.getCode(), error.getMessage()));
             }

             for (EditorialError error : ex.getFaultInfo().getEditorialErrors().getEditorialErrors())
             {
                 outputStatusMessage(String.format("EditorialError at Index: %d\n\n", error.getIndex()));
                 outputStatusMessage(String.format("Code: %d\nMessage: %s\n\n", error.getCode(), error.getMessage()));
                 outputStatusMessage(String.format("Appealable: %s\nDisapproved Text: %s\nCountry: %s\n\n", 
                         error.getAppealable(), error.getDisapprovedText(), error.getPublisherCountry()));
             }

             for (OperationError error : ex.getFaultInfo().getOperationErrors().getOperationErrors())
             {
                 outputStatusMessage("OperationError\n");
                 outputStatusMessage(String.format("Code: %d\nMessage: %s\n\n", error.getCode(), error.getMessage()));
             }
         } catch (RemoteException ex) {
             outputStatusMessage("Service communication error encountered: ");
             outputStatusMessage(ex.getMessage());
             ex.printStackTrace();
         } catch (Exception ex) {
             outputStatusMessage("Error encountered: ");
             outputStatusMessage(ex.getMessage());
             ex.printStackTrace();
         }
     }

     // Adds one or more campaigns to the specified account.

     static AddCampaignsResponse addCampaigns(long accountId, ArrayOfCampaign campaigns) throws RemoteException, Exception
     {
         AddCampaignsRequest request = new AddCampaignsRequest();

         // Set the request information.

         request.setAccountId(accountId);
         request.setCampaigns(campaigns);

         return CampaignService.getService().addCampaigns(request);
     }

     // Deletes one or more campaigns from the specified account.

     static void deleteCampaigns(long accountId, ArrayOflong campaignIds) throws RemoteException, Exception
     {
         DeleteCampaignsRequest request = new DeleteCampaignsRequest();

         // Set the request information.

         request.setAccountId(accountId);
         request.setCampaignIds(campaignIds);

         CampaignService.getService().deleteCampaigns(request);
     }

     // Adds one or more ad extensions to the account's ad extension library.

     static ArrayOfAdExtensionIdentity addAdExtensions(long accountId, ArrayOfAdExtension adExtensions) throws RemoteException, Exception
     {
         AddAdExtensionsRequest request = new AddAdExtensionsRequest();

         // Set the request information.

         request.setAccountId(accountId);
         request.setAdExtensions(adExtensions);

         return CampaignService.getService().addAdExtensions(request).getAdExtensionIdentities();
     }

     // Deletes one or more ad extensions from the account’s ad extension library.

     static void deleteAdExtensions(long accountId, ArrayOflong adExtensionIds) throws RemoteException, Exception
     {
         DeleteAdExtensionsRequest request = new DeleteAdExtensionsRequest();

         // Set the request information.

         request.setAccountId(accountId);
         request.setAdExtensionIds(adExtensionIds);

         CampaignService.getService().deleteAdExtensions(request);
     }

     // Associates one or more extensions with the corresponding campaign or ad group entities.

     static void setAdExtensionsAssociations(long accountId, ArrayOfAdExtensionIdToEntityIdAssociation associations, AssociationType associationType) throws RemoteException, Exception
     {
         SetAdExtensionsAssociationsRequest request = new SetAdExtensionsAssociationsRequest();

         // Set the request information.

         request.setAccountId(accountId);
         request.setAdExtensionIdToEntityIdAssociations(associations);
         request.setAssociationType(associationType);

         CampaignService.getService().setAdExtensionsAssociations(request);
     }

     // Removes the specified association from the respective campaigns or ad groups.

     static void deleteAdExtensionsAssociations(long accountId, ArrayOfAdExtensionIdToEntityIdAssociation associations, AssociationType associationType) throws RemoteException, Exception
     {
         DeleteAdExtensionsAssociationsRequest request = new DeleteAdExtensionsAssociationsRequest();

         // Set the request information.

         request.setAccountId(accountId);
         request.setAdExtensionIdToEntityIdAssociations(associations);
         request.setAssociationType(associationType);

         CampaignService.getService().deleteAdExtensionsAssociations(request);
     }

     // Gets the specified ad extensions from the account's extension library.

     static ArrayOfAdExtension getAdExtensionsByIds(long accountId, ArrayOflong adExtensionIds, ArrayList<AdExtensionsTypeFilter> adExtensionsTypeFilter) throws RemoteException, Exception
     {
         GetAdExtensionsByIdsRequest request = new GetAdExtensionsByIdsRequest();

         // Set the request information.

         request.setAccountId(accountId);
         request.setAdExtensionIds(adExtensionIds);
         request.setAdExtensionType(adExtensionsTypeFilter);

         return CampaignService.getService().getAdExtensionsByIds(request).getAdExtensions();
     }

     // Gets the reasons why the specified extension failed editorial when 
     // in the context of an associated campaign or ad group.

     private static ArrayOfAdExtensionEditorialReasonCollection getAdExtensionsEditorialReasons(
         long accountId,
         ArrayOfAdExtensionIdToEntityIdAssociation associations,
         AssociationType associationType)  throws RemoteException, Exception
     {
         GetAdExtensionsEditorialReasonsRequest request = new GetAdExtensionsEditorialReasonsRequest();

         // Set the request information.

         request.setAccountId(accountId);
         request.setAdExtensionIdToEntityIdAssociations(associations);
         request.setAssociationType(associationType);

         return CampaignService.getService().getAdExtensionsEditorialReasons(request).getEditorialReasons();
     }   

  // Prints the campaign identifiers, as well as any partial errors

     static void outputCampaignsWithPartialErrors(ArrayOfCampaign campaigns, ArrayOfNullableOflong campaignIds, ArrayOfBatchError partialErrors)
     {
         if (campaignIds == null)
         {
             return;
         }

         // Print the identifier of each successfully added campaign.

         for (int index = 0; index < campaigns.getCampaigns().size(); index++ )
         {
             // The array of keyword identifiers equals the size of the attempted campaigns. If the element 
             // is not null, the campaign at that index was added successfully and has a campaign identifier. 

             if (campaignIds.getLongs().get(index) != null)
             {
                 outputStatusMessage(String.format("Campaign[%d] (Name:%s) successfully added and assigned CampaignId %d\n", 
                     index,  
                     campaigns.getCampaigns().get(index).getName(),
                     campaignIds.getLongs().get(index)));
             }
         }

         // Print the error details for any campaign not successfully added.
         // Note also that multiple error reasons may exist for the same attempted campaign.

         for (BatchError error : partialErrors.getBatchErrors())
         {
             // The index of the partial errors is equal to the index of the list
             // specified in the call to AddCampaigns.

             outputStatusMessage(String.format("\nCampaign[%d] (Name:%s) not added due to the following error:\n", 
                     error.getIndex(), campaigns.getCampaigns().get(error.getIndex()).getName()));

             outputStatusMessage(String.format("\tIndex: %d\n", error.getIndex()));
             outputStatusMessage(String.format("\tCode: %d\n", error.getCode()));
             outputStatusMessage(String.format("\tErrorCode: %s\n", error.getErrorCode()));
             outputStatusMessage(String.format("\tMessage: %s\n", error.getMessage()));

             // In the case of an EditorialError, more details are available
             if (error.getType().equals("EditorialError") && error.getErrorCode().equals("CampaignServiceEditorialValidationError"))
             {
                 outputStatusMessage(String.format("\tDisapprovedText: %s\n", ((EditorialError)(error)).getDisapprovedText()));
                 outputStatusMessage(String.format("\tLocation: %s\n", ((EditorialError)(error)).getLocation()));
                 outputStatusMessage(String.format("\tPublisherCountry: %s\n", ((EditorialError)(error)).getPublisherCountry()));
                 outputStatusMessage(String.format("\tReasonCode: %d\n", ((EditorialError)(error)).getReasonCode()));
             }
         }

         outputStatusMessage("");
     }

     static void outputAppAdExtension(AppAdExtension extension){
        if (extension != null) {
            outputStatusMessage(String.format("Id: %s", extension.getId()));
            outputStatusMessage(String.format("Status: %s", extension.getStatus()));
            outputStatusMessage(String.format("Version: %s", extension.getVersion()));
            outputStatusMessage(String.format("AppPlatform: %s", extension.getAppPlatform()));
            outputStatusMessage(String.format("AppStoreId: %s", extension.getAppStoreId()));
            outputStatusMessage(String.format("DestinationUrl: %s", extension.getDestinationUrl()));
            outputStatusMessage(String.format("DevicePreference: %s", extension.getDevicePreference()));
            outputStatusMessage(String.format("DisplayText: %s", extension.getDisplayText()));
        }
    }

     static void outputCallAdExtension(CallAdExtension extension){
        if (extension != null) {
            outputStatusMessage(String.format("Id: %s", extension.getId()));
            outputStatusMessage(String.format("Status: %s", extension.getStatus()));
            outputStatusMessage(String.format("Version: %s", extension.getVersion()));
            outputStatusMessage(String.format("Phone number: %s", extension.getPhoneNumber()));
             outputStatusMessage(String.format("Country: %s", extension.getCountryCode()));
             outputStatusMessage(String.format("Is only clickable item: %s", extension.getIsCallOnly()));
        }
    }

    static void outputLocationAdExtension(LocationAdExtension extension){
        if (extension != null) {
             outputStatusMessage(String.format("Id: %s", extension.getId()));
            outputStatusMessage(String.format("Status: %s", extension.getStatus()));
            outputStatusMessage(String.format("Version: %s", extension.getVersion()));
            if(extension.getAddress() != null){
                outputStatusMessage(String.format("Street: %s", extension.getAddress().getStreetAddress()));
                outputStatusMessage(String.format("City: %s", extension.getAddress().getCityName()));
                outputStatusMessage(String.format("State: %s", extension.getAddress().getProvinceName()));
                outputStatusMessage(String.format("Country: %s", extension.getAddress().getCountryCode()));
                outputStatusMessage(String.format("Zip code: %s", extension.getAddress().getPostalCode()));
            }
            outputStatusMessage(String.format("Company name: %s", extension.getCompanyName()));
             outputStatusMessage(String.format("Phone number: %s", extension.getPhoneNumber()));
             outputStatusMessage(String.format("Business coordinates determined?: %s", extension.getGeoCodeStatus()));
             if(extension.getGeoPoint() != null){
                outputStatusMessage("GeoPoint: ");
                outputStatusMessage(String.format("\tLatitudeInMicroDegrees: %s", 
                        extension.getGeoPoint().getLatitudeInMicroDegrees()));
                outputStatusMessage(String.format("\tLongitudeInMicroDegrees: %s", 
                        extension.getGeoPoint().getLongitudeInMicroDegrees()));
             }
             outputStatusMessage(String.format("Map icon ID: %s", extension.getIconMediaId()));
             outputStatusMessage(String.format("Business image ID: %s", extension.getImageMediaId()));
        }
    }

    static void outputSiteLinksAdExtension(SiteLinksAdExtension extension){
        if (extension != null && extension.getSiteLinks() != null) {
            outputStatusMessage(String.format("Id: %s", extension.getId()));
            outputStatusMessage(String.format("Status: %s", extension.getStatus()));
            outputStatusMessage(String.format("Version: %s", extension.getVersion()));

            outputSiteLinks(extension.getSiteLinks().getSiteLinks());
        }
    }

    static void outputSiteLinks(Iterable<SiteLink> siteLinks){
        if (siteLinks != null) {
            for (SiteLink siteLink : siteLinks)
             {
                outputStatusMessage(String.format("DisplayText: %s", siteLink.getDisplayText()));
                 outputStatusMessage(String.format("DestinationUrl: %s", siteLink.getDestinationUrl()));
                 outputStatusMessage("FinalMobileUrls: ");
                 if (siteLink.getFinalMobileUrls() != null)
                 {
                     for (java.lang.String finalMobileUrl : siteLink.getFinalMobileUrls().getStrings())
                     {
                         outputStatusMessage(String.format("\t%s", finalMobileUrl));
                     }
                 }

                 outputStatusMessage("FinalUrls: ");
                 if (siteLink.getFinalUrls() != null)
                 {
                     for (java.lang.String finalUrl : siteLink.getFinalUrls().getStrings())
                     {
                         outputStatusMessage(String.format("\t%s", finalUrl));
                     }
                 }
                 outputStatusMessage(String.format("TrackingUrlTemplate: %s", siteLink.getTrackingUrlTemplate()));
                 outputStatusMessage("UrlCustomParameters: ");
                 if (siteLink.getUrlCustomParameters() != null &&
                        siteLink.getUrlCustomParameters().getParameters() != null)
                 {
                     for (CustomParameter customParameter : siteLink.getUrlCustomParameters().getParameters().getCustomParameters())
                     {
                        outputStatusMessage(String.format("\tKey: %s", customParameter.getKey()));
                        outputStatusMessage(String.format("\tValue: %s", customParameter.getValue()));
                     }
                 }
                 outputStatusMessage("");
             }
        }
    }
 }

Getting Started Using Java with Bing Ads ServicesCampaign Setup and BasicsAd Extensions

Show: