Большое спасибо за то, что прочитали этот пост, мы будем благодарны за любую помощь !!
Я пытаюсь использовать учетную запись службы для создания списка и создания текстового файла на Диске. Создал учетную запись службы, загрузил файл p12, также включил Drive api для учетной записи. Но я получаю исключение SSLHandshakeException.
Версия Googleapi: libs-sources / google-api-services-drive-v2-rev168-1.20.0-sources.jar
версия java: "1.7.0_79" Среда выполнения Java (TM) SE (сборка 1.7.0_79-b15) 64-разрядная серверная виртуальная машина Java HotSpot (TM) (сборка 24.79-b02, смешанный режим)
Также загрузили загруженный файл p12 в файл cacerts в \ jdk1.7.0_79 \ jre \ lib \ security.
Произошла ошибка: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: сбой построения пути PKIX: sun.security.provider.certpath.SunCertPathBuilderException: не удалось найти допустимый путь сертификации для запрошенного целевого исключения в потоке «main» javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: сбой построения пути PKIX: sun.security.provider.certpath.SunCertPathBuilderException: невозможно найти действительный путь сертификации к запрошенной цели в sun.security.ssl.Alerts.getSSLException (Неизвестный источник) ........... Вызвано: sun.security.validator.ValidatorException: сбой построения пути PKIX: sun.security.provider.certpath.SunCertPathBuilderException: невозможно найти действительный путь сертификации для запрошенной цели at sun.security.validator.PKIXValidator.doBuild (Неизвестный источник) ................ Вызвано: sun.security.provider.certpath.SunCertPathBuilderException: невозможно найти действительный путь сертификации для запрошенная цель в sun.security.provider.certpath.SunCertPathBuilder.engineBuild (неизвестный источник)
Вот мой исходный код:
private static void getSomethingFromDrive() throws Exception {
String emailAddress ="[email protected]";
JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
GoogleCredential.Builder credBuilder = new GoogleCredential.Builder();
credBuilder.setTransport(httpTransport);
credBuilder.setJsonFactory(JSON_FACTORY);
credBuilder.setServiceAccountId(emailAddress);
credBuilder.setServiceAccountPrivateKeyFromP12File(new File("XXXXX.p12"));
credBuilder.setServiceAccountScopes(Arrays.asList(DriveScopes.DRIVE));
GoogleCredential credential = credBuilder.build();
Drive service = new Drive.Builder(httpTransport, JSON_FACTORY, credential).build();
DriveOperation.printAbout(service);
//Insert a file
com.google.api.services.drive.model.File body = new com.google.api.services.drive.model.File();
body.setTitle("My document");
body.setDescription("A test document");
body.setMimeType("text/plain");
java.io.File fileContent = new java.io.File("C:/Personal/document.txt");
FileContent mediaContent = new FileContent("text/plain", fileContent);
com.google.api.services.drive.model.File file = service.files().insert(body, mediaContent).execute();
System.out.println("File ID: " + file.getId());
}