java.io.IOException:在创建GoogleCredential对象时解码PKCS 12输入时出错

时间:2017-03-09 15:48:32

标签: java google-analytics google-analytics-api google-analytics-v4

在创建凭证对象时,当它尝试从p12设置私钥时,它会失败并显示错误“java.io.IOException:解码PKCS 12输入时出错”:

InputStream content = ..... // logic to get input stream  
File file = new File("Analytics-data-retrieval.p12");  
FileUtils.copyInputStreamToFile(content, file);

GoogleCredential credential = new GoogleCredential.Builder()
            .setTransport(httpTransport)
            .setJsonFactory(JSON_FACTORY)
            .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
            .setServiceAccountPrivateKeyFromP12File(file)
            .setServiceAccountScopes(AnalyticsReportingScopes.all())
            .build();

0 个答案:

没有答案