// Required libraries
import com.google.api.client.googleapis.batch.BatchRequest;
import com.google.api.client.googleapis.batch.json.JsonBatchCallback;
import com.google.api.client.googleapis.json.GoogleJsonError;
// 1. Define callback function with actions to take on success & fail
private JsonBatchCallback<Void> setCallback(final String successMessage){
JsonBatchCallback<Void> callback = new JsonBatchCallback<Void>(){
@Override
public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders)
throws IOException {
System.out.println(e.getMessage());
}
public void onSuccess(Void t, HttpHeaders responseHeaders)
throws IOException {
System.out.println(successMessage);
}
};
return callback;
}
// 2. Initialise batch
BatchRequest batchRequest = analytics.batch();
// 3. Define action to take
analytics.management().profileUserLinks().delete(accountId, webPropertyId, profileId, linkId)
// 4. Add to batch using queue(BatchRequest, JsonBatchCallback<Void>)
.queue(batchRequest, setCallback(userEmail + " deleted from profile ID " + profileId));
// 5. Run batch
batch.execute();