我目前有一个非常简单的功能,可以利用Java API(在Scala中)创建一个google存储桶。但是,它目前从环境中推断出gCloud凭据。
def createBucket(bucketName: String) = {
val storage = StorageOptions.getDefaultInstance.getService // May need to change. Creds inferred from environment.
val bucket = storage.create(BucketInfo.of(bucketName))
}
有没有办法将GoogleCredential
对象传递给构造函数?踩过API @ https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-storage/src/main/java/com/google/cloud/storage,但没有运气。
答案 0 :(得分:1)
找到https://github.com/GoogleCloudPlatform/google-cloud-java#authentication
中列出的答案Storage storage = StorageOptions.newBuilder()
.setCredentials(new GoogleCredentials(new AccessToken(accessToken, expirationTime)))
.build()
.getService();