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());
}
}
Aggregations