Search in sources :

Example 1 with CampaignLabelOperation

use of com.google.api.ads.adwords.axis.v201809.cm.CampaignLabelOperation in project googleads-java-lib by googleads.

the class AddCampaignLabels method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignIds the IDs of the campaigns to which the label will be added.
 * @param labelId the ID of the label to attach to campaigns.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, List<Long> campaignIds, Long labelId) throws RemoteException {
    // Get the CampaignService.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
    // Create label operations.
    List<CampaignLabelOperation> operations = new ArrayList<>(campaignIds.size());
    for (Long campaignId : campaignIds) {
        CampaignLabel campaignLabel = new CampaignLabel();
        campaignLabel.setCampaignId(campaignId);
        campaignLabel.setLabelId(labelId);
        CampaignLabelOperation operation = new CampaignLabelOperation();
        operation.setOperand(campaignLabel);
        operation.setOperator(Operator.ADD);
        operations.add(operation);
    }
    // Display campaign labels.
    for (CampaignLabel campaignLabelResult : campaignService.mutateLabel(operations.toArray(new CampaignLabelOperation[operations.size()])).getValue()) {
        System.out.printf("Campaign label for campaign ID %d and label ID %d was added.%n", campaignLabelResult.getCampaignId(), campaignLabelResult.getLabelId());
    }
}
Also used : CampaignServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface) CampaignLabelOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignLabelOperation) ArrayList(java.util.ArrayList) CampaignLabel(com.google.api.ads.adwords.axis.v201809.cm.CampaignLabel)

Aggregations

CampaignLabel (com.google.api.ads.adwords.axis.v201809.cm.CampaignLabel)1 CampaignLabelOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignLabelOperation)1 CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)1 ArrayList (java.util.ArrayList)1