Java 设置google凭据的证书文件,不使用文件

Java 设置google凭据的证书文件,不使用文件,java,google-app-engine,oauth,jersey,Java,Google App Engine,Oauth,Jersey,班级: com.google.api.client.googleapis.auth.oauth2.GoogleCredential 创建实例时需要 我在google app engine上使用Jersey,如果我使用guava资源打开我的文件(在参考资料中),一切都可以在本地正常工作,但是在部署到app engine时,我得到了 所以我应该使用getResourceAsStream和 但谷歌应用引擎限制了FileOutputStream的使用(不允许使用) 是否有任何方法可以从inputstre

班级: com.google.api.client.googleapis.auth.oauth2.GoogleCredential 创建实例时需要

我在google app engine上使用Jersey,如果我使用guava资源打开我的文件(在参考资料中),一切都可以在本地正常工作,但是在部署到app engine时,我得到了

所以我应该使用getResourceAsStream和

但谷歌应用引擎限制了FileOutputStream的使用(不允许使用)


是否有任何方法可以从inputstream创建临时文件而不使用FileOutputStream。。。或者是否有人熟悉使用google OAuth api的不同方式在部署的应用程序引擎中执行此操作的正确方式是:

Collection<String> scopes = new ArrayList<>(1);
scopes.add("https://www.googleapis.com/auth/bigquery");
AppIdentityCredential credential = new AppIdentityCredential(scopes);
Bigquery bigquery = new Bigquery.Builder(new NetHttpTransport(), new GsonFactory(), credential).setApplicationName("myAppName").build();

无论您采用何种方式,都无法在应用程序引擎上创建文件。您可能希望使用Blobstore来保存类似的内容,或者将文件保存到GCS本身。由于应用程序引擎可以(也将)将您的应用程序从一个实例移动到另一个实例,因此让您的应用程序接触文件系统是不安全的,而且非常复杂
String account = properties.get("oauthAccount");
String clientId = properties.get("oauthClientId");
String secret = properties.get("oauthSecret");
File privateKey = getCertficateFile();
GoogleCredential.Builder builder = new GoogleCredential.Builder();
builder.setTransport(new NetHttpTransport());
builder.setServiceAccountId(account);
builder.setJsonFactory(new GsonFactory());
builder.setClientSecrets(clientId, secret);            
builder.setServiceAccountScopes(Arrays.asList("https://www.googleapis.com/auth/bigquery"));
builder.setServiceAccountPrivateKeyFromP12File(privateKey);
GoogleCredential googleBigQueryCredential = builder.build();
Bigquery bigquery = new Bigquery.Builder(new NetHttpTransport(), new GsonFactory(), googleBigQueryCredential).setApplicationName("myAppName")                                                                                                                     .build();