private static final String ADVERTISER_COMPANY_ID = "INSERT_ADVERTISER_COMPANY_ID_HERE";
public static void runExample(DfpServices dfpServices, DfpSession session,
int activityGroupId, long advertiserCompanyId) throws Exception {
// Get the ActivityGroupService.
ActivityGroupServiceInterface activityGroupService =
dfpServices.get(session, ActivityGroupServiceInterface.class);
// Get the activity group.
ActivityGroup activityGroup = activityGroupService.getActivityGroup(activityGroupId);
// Update the companies.
activityGroup.setCompanyIds(
Longs.concat(activityGroup.getCompanyIds(), new long[] {advertiserCompanyId}));
// Update the activity group on the server.
ActivityGroup[] activityGroups =
activityGroupService.updateActivityGroups(new ActivityGroup[] {activityGroup});
for (ActivityGroup updatedActivityGroup : activityGroups) {
System.out.printf(
"Activity group with ID \"%d\" and name \"%s\" was updated.\n",
updatedActivityGroup.getId(), updatedActivityGroup.getName());