设置 google 凭据的证书文件,不使用文件
set Certificate file of google credentials, without using file
class :
com.google.api.client.googleapis.auth.oauth2.GoogleCredential
创建实例时需要 certifcate file as a parameter。
我在 google 应用引擎上使用 Jersey,如果我使用番石榴资源打开我的文件(在资源中),在本地一切正常,但是在部署到应用引擎时我得到 URI is not Hierarchical error .
所以我应该使用 getResourceAsStream 和 convert to temporary file ...
但是 google 应用引擎限制了 FileOutputStream 的使用(不允许使用)。
是否有任何方法可以在不使用 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();
这与本地 dev/when 测试推荐的方式不同 - 依赖于文件引用(因此您有不同的 testing/production 代码):
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();
class : com.google.api.client.googleapis.auth.oauth2.GoogleCredential 创建实例时需要 certifcate file as a parameter。
我在 google 应用引擎上使用 Jersey,如果我使用番石榴资源打开我的文件(在资源中),在本地一切正常,但是在部署到应用引擎时我得到 URI is not Hierarchical error .
所以我应该使用 getResourceAsStream 和 convert to temporary file ...
但是 google 应用引擎限制了 FileOutputStream 的使用(不允许使用)。
是否有任何方法可以在不使用 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();
这与本地 dev/when 测试推荐的方式不同 - 依赖于文件引用(因此您有不同的 testing/production 代码):
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();