如果使用默认凭据创建,则只能使用此环境变量
(example in python)
import google.auth
credentials,project_id = google.auth.default()
现在,请考虑您在GOOGLE_APPLICATION_CREDENTIALS环境变量中输入的值。它只是服务帐户密钥文件的路径。因此,you can do that,which is equivalent to the previous command
import google.auth
credentials = service_account.Credentials.from_service_account_file(os.getenv('GOOGLE_APPLICATION_CREDENTIALS'))
因此,您可以使用所需的env var名称,并通过将路径传递到正确的文件来创建显式凭证!
C#示例:
var credentials = GoogleCredential.FromFile(@"c:\certs\trigger-sa.json");
var storageClient = StorageClient.Create(credentials);
本文链接:https://www.f2er.com/1974775.html