问题
I have access and a secret key to Google Cloud Storage and I want to instantiate a client using those credentials. I've been looking at tutorials and came across this example:
public class QuickstartSample {
public static void main(String... args) throws Exception {
// Instantiates a client
Storage storage = StorageOptions.getDefaultInstance().getService();
/* Perform some bucket action */
}
}
Is there any way I could pass that access
and secret
key while instantiating a client, in a fashion similar to that of AWS
and Minio
, something like this:
minioClient = new MinioClient("server URL", "accessKey",
"secretKey");
I'd really appreciate some help with this.
回答1:
As you can see in this link, "you don't need to explicitly specify your credentials in code when using a Google Cloud Client Library".
There are though some other options to authenticate you client in your code, but none of them use access and secret key as it happens in AWS buckets, for instance. Here you have a number of options to implement that authentication in your code, such as using the JSON service account key within your code or using an OAuth2 access token.
来源:https://stackoverflow.com/questions/55176694/how-can-i-get-access-to-google-cloud-storage-using-an-access-and-a-secret-key