How to Setup DialogFlow V2 Authentication Programmatically with java/android

export GOOGLE_APPLICATION_CREDENTIALS=absolute/path/of/key.json
  1. add dependencies in gradle file. If you using maven then add the corresponding dependencies in pom.xml
implementation group: 'com.google.api', name: 'gax', version: '1.5.0'
implementation group: 'com.google.cloud', name: 'google-cloud-dialogflow', version: '2.0.0'
implementation group: 'io.grpc', name: 'grpc-core', version: '1.30.0'
implementation group: 'io.grpc', name: 'grpc-api', version: '1.30.0'
implementation group: 'io.grpc', name: 'grpc-okhttp', version: '1.30.0'
FileInputStream stream = new FileInputStream(new File("/absolute/path/to/key.json"));
GoogleCredentials credentials = GoogleCredentials.fromStream(stream);
String projectId = ((ServiceAccountCredentials)credentials).getProjectId();
SessionsSettings.Builder settingsBuilder = SessionsSettings.newBuilder();
SessionsSettings sessionsSettings = settingsBuilder.setCredentialsProvider(FixedCredentialsProvider.create(credentials)).build();

SessionsClient sessionsClient = SessionsClient.create(sessionsSettings);
String sessionId = UUID.randomUUID().toString();
SessionName session = SessionName.of(projectId, sessionId);

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store