我有一个导入 jar 的应用程序引擎应用程序。在那个 jar 中,我使用 GoogleClientSecrets.load() 加载 client_secrets.json 文件以使用 BigQuery 进行身份验证。显然,当我在 localhost 上部署应用程序时,App Engine 不喜欢我从磁盘上的某个位置读取文件。我假设如果我将凭据放在 WEBINF 文件夹中,它将起作用,但尚未对其进行测试,但是任何人都可以轻松访问该文件。放置凭据的最佳位置在哪里?如何从 App Engine 应用程序访问它们?
谢谢您的帮助!
这些建议有助于解决读取文件时的问题。写入文件呢?我正在使用 FileCredentialStore 存储凭据文件。
我相信这条线导致了一个问题: FileCredentialStore variantStoreCredentialManager = new FileCredentialStore(expectedClientFile,jsonFactory); 错误是 java.security.AccessControlException: access denied ("java.io.FilePermission" file path "write")
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);
}