0

The class : com.google.api.client.googleapis.auth.oauth2.GoogleCredential Requires a certifcate file as a parameter when creatign an instance.

I am using Jersey on google app engine, if I open my file (which is in resources) using guava Resources everything works fine locally, however on deployment to app engine I get URI is not Hierarchical error.

So I should use getResourceAsStream and convert to temporary file ...

BUT google app engine restricts usage of FileOutputStream (its not allowed to be used).

Is there any way to create a temp file from an inputstream without using FileOutputStream ... or is anyone familar with a different way of using the google OAuth api

Community
  • 1
  • 1
NimChimpsky
  • 46,453
  • 60
  • 198
  • 311
  • you won't be able to create a file on the App Engine, no matter what way you do. You might want to use Blobstore to save something like that, or save the file on GCS itself. Since the App Engine can (and WILL) move your application from instance to instance, it would be unsafe and really complicated to have your app touch the filesystem – Patrice Feb 13 '15 at 19:32

1 Answers1

0

The correct way to do this in the deployed app engine is :

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();

Which is different to way recommended for local dev/when testing - that relies on a File reference (so you have different code for 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();
NimChimpsky
  • 46,453
  • 60
  • 198
  • 311