Skip to content

Instantly share code, notes, and snippets.

@sakama
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sakama/3203a7843cb52064e408 to your computer and use it in GitHub Desktop.
Save sakama/3203a7843cb52064e408 to your computer and use it in GitHub Desktop.
GoogleCredentialクラスを使ったGCSの認証
private final HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
private final JsonFactory jsonFactory = new JacksonFactory();
private hoge() throws IOException, GeneralSecurityException
{
GoogleCredential credentials = new GoogleCredential.Builder().setTransport(httpTransport) // (1)
.setJsonFactory(jsonFactory)
.setServiceAccountId(<サービスアカウント メールアドレス>)
.setServiceAccountScopes( // (2)
ImmutableList.of(
StorageScopes.DEVSTORAGE_READ_ONLY
BigqueryScopes.BIGQUERY
)
)
.setServiceAccountPrivateKeyFromP12File(new File(<P12秘密鍵のフルパス>))
.build();
Storage client = new Storage.Builder(httpTransport, jsonFactory, credentials)
.setApplicationName(<アプリケーション名>) // (3)
.build();
return client;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment