当前位置: 首页 > 知识库问答 >
问题:

服务帐户抛出-SSLHandshakeException

李胡媚
2023-03-14

Googleapi版本: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(build 24.79-B02,混合模式)

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

这里是我的源代码:

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());

}

共有1个答案

劳法
2023-03-14

听起来像是密钥库的问题。您是否将证书导入到.jks文件中?

嗯。我做了一些快速的研究,听起来它应该起作用。您能够查看您在CACERTS中添加的证书吗?

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

 类似资料:
  • 这会给出以下输出{“error”:{“error”:[{“domain”:“global”,“reason”:“autherror”,“message”:“invalid credentials”,“locationtype”:“header”,“location”:“authorization”}],“code”:401,“message”:“invalid credentials”}} 有人能

  • 我正在尝试通过服务帐户(客户端电子邮件和p12证书)连接到google doubeclick api,使用python客户端库,如以下示例所示: http://code.google.com/p/google-api-python-client/source/browse/samples/service_account/tasks.py 它给我一个空access_token: 这有什么意义?我有没

  • 我想用gmail API阅读我的gmail收件箱。我需要使用服务帐户,因为我的应用程序没有用户交互。我在请求时收到以下错误: 这是我的代码: 我做错了什么?有人能帮我吗? 当做

  • 我正在使用谷歌服务帐户将MySQL备份从我们的网络服务器推送到谷歌云端硬盘,使用谷歌API PHP客户端脚本设置为cron作业。 我现在想在多个网络服务器上运行相同的脚本,我不知道如何正确配置服务号,应该吗? > 是否在所有服务器上使用相同的服务帐户和服务帐户密钥/凭据? 或者使用相同的服务帐户,但为每个服务器添加服务帐户密钥/凭据? 还是为每台服务器设置单独的服务帐户?

  • 我开发了以下代码,用于自动执行我的一些实例的启动/停止任务,这些实例不需要一直运行,而是在特定范围内运行。 这是我的代码:https://github.com/maartinpii/gcp-shst 我按照谷歌云平台指南(参考:https://cloud.google.com/iam/docs/understanding-service-accounts https://cloud.google.

  • 我目前正在研究Office 365 API。是否可以创建一个服务帐户,该帐户将代表应用程序而不是用户调用API? 谷歌有以下内容:https://developers.google.com/accounts/docs/OAuth2#serviceaccount 谢谢 感谢您回复我。是否可以使用API执行以下操作。我想这是我在另一个博客上读到的,但我只是想证实这一点。http://blogs.msd