如果其他人看到这个并想知道我是如何解决它的... Atlassian 开发人员指出我的主要问题是我只是将 .p12 文件放在根资源目录中。一旦我把它放到那里自己的文件夹中,它就像一个魅力。我让这一切正常工作的最终代码(在其他 Stack Overflow 问题的帮助下)
String sheetURL = "XXXXXX@XXXXXX-XXXX.iam.gserviceaccount.com";
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
String[] SCOPESArray = {"https://spreadsheets.google.com/feeds", "https://spreadsheets.google.com/feeds/spreadsheets/private/full", "https://docs.google.com/feeds"};
final List SCOPES = Arrays.asList(SCOPESArray);
GoogleCredential credential = null;
InputStream stream = null;
File tempFile = null;
try {
stream = this.getClass().getClassLoader().getResourceAsStream("authentication/key.p12");
tempFile = File.createTempFile("temp", "temp");
IOUtils.copy(stream, new FileOutputStream(tempFile));
}
catch (IOException e) {
print(e.toString());
}
finally {
if (stream != null) {
IOUtils.closeQuietly(stream);
}
}
credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(sheetURL)
.setServiceAccountScopes(SCOPES)
.setServiceAccountPrivateKeyFromP12File(tempFile)
.build();