gpt4 book ai didi

java - 服务帐户抛出 - SSLHandshakeException

转载 作者:太空宇宙 更新时间:2023-11-03 14:49:24 26 4
gpt4 key购买 nike

非常感谢您阅读这篇文章,我们将不胜感激!

我正在尝试使用服务帐户在云端硬盘中列出和创建一个文本文件。已经生成了一个服务帐户,下载了 p12 文件也为该帐户启用了 Drive api。但是我收到了 SSLHandshakeException。

谷歌 API 版本:libs-sources/google-api-services-drive-v2-rev168-1.20.0-sources.jar

Java 版本:“1.7.0_79”Java(TM) SE 运行时环境(build 1.7.0_79-b15)Java HotSpot(TM) 64 位服务器 VM(构建 24.79-b02,混合模式)

也将下载的p12文件加载到\jdk1.7.0_79\jre\lib\security下的cacerts文件中。

发生错误:javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径线程“主”中的异常 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:无法找到请求目标的有效证书路径 在 sun.security.validator.PKIXValidator.doBuild(未知来源).....................原因:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径 在 sun.security.provider.certpath.SunCertPathBuilder.engineBuild(未知来源)

这是我的源代码:

private static void getSomethingFromDrive() throws Exception {

String emailAddress ="XXXXXtest@XXXXX.iam.gserviceaccount.com";
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());

}

最佳答案

听起来像是 keystore 问题。您是否将证书导入 .jks 文件?

嗯。我做了一些快速研究,听起来应该可行。您是否可以查看您在 cacerts 中添加的证书?

或者它是否可能指向 jre cacerts 而不是 jdk cacerts?

关于java - 服务帐户抛出 - SSLHandshakeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35809843/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com