Last active
August 29, 2015 14:17
-
-
Save sakama/3203a7843cb52064e408 to your computer and use it in GitHub Desktop.
GoogleCredentialクラスを使ったGCSの認証
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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