我有一個應用程序引擎應用程序,它導入了一個jar。在該jar中,我使用 GoogleClientSecrets.load() 加載client_secrets.json文件以使用BigQuery進行身份驗證。顯然,當我在本地部署應用程序時,App Engine不喜歡從磁盤上的某個位置讀取文件。我假設如果我把證書放在WEBINF文件夾中,它會起作用,但還沒有測試過,但是任何人都可以輕鬆地訪問這個文件。哪裏是放置證書的最佳地點,以及如何從App Engine應用程序訪問它們?App Engine憑據問題
謝謝你的幫助!
這些建議有助於解決讀取文件時遇到的問題。如何寫入文件?我正在使用存儲憑證文件的FileCredentialStore。
我相信這行是造成一個問題: FileCredentialStore variantStoreCredentialManager = new FileCredentialStore(expectedClientFile,jsonFactory); 且誤差 java.security.AccessControlException:訪問被拒絕(「java.io.FilePermission中的」文件路徑「寫入」)
public Bigquery createAuthorizedClient() throws IOException {
Credential authorization = new GoogleCredential();
if (clientID == null) {
authorization = createWebAuthenticatedClientCredential();
} else {
String expectedFileLocation = CREDENTIAL_FILE_PATH;
File expectedClientFile = new File(expectedFileLocation);
if (! expectedClientFile.exists()) {
// this is a known issue, the credential store will blow up if the file doesn't exist. So create it with an
// empty json ({ })
createClientFile(expectedClientFile);
}
FileCredentialStore variantStoreCredentialManager = new FileCredentialStore(expectedClientFile,jsonFactory);
GoogleCredential.Builder credentialBuilder = new GoogleCredential.Builder();
credentialBuilder.setJsonFactory(jsonFactory);
credentialBuilder.setClientSecrets(clientSecrets);
credentialBuilder.setTransport(transport);
authorization = credentialBuilder.build();
boolean loadedSuccessfully = variantStoreCredentialManager.load(clientID,authorization);
if (! loadedSuccessfully ) {
authorization = createWebAuthenticatedClientCredential();
variantStoreCredentialManager.store(clientID, authorization);
}
}
return new Bigquery(transport, jsonFactory, authorization);
}
'/ WEB-INF'是放置這些數據的正確位置。訪問它作爲資源,而不是文件:http://stackoverflow.com/questions/4340653/file-path-to-resource-in-our-war-web-inf-folder –
謝謝你的回覆 – Tad