【问题标题】:How do I authenticate the with the Google Storage SDK using a JSON service account key?如何使用 JSON 服务帐户密钥对 Google Storage SDK 进行身份验证?
【发布时间】:2018-01-17 16:30:07
【问题描述】:

我正在查看位于以下位置的 API 参考:

https://googlecloudplatform.github.io/google-cloud-python/latest/storage/client.html

在使用服务帐户时,我应该如何进行身份验证?我看不到如何创建必要的Credentials 对象。

【问题讨论】:

    标签: python google-cloud-storage


    【解决方案1】:

    https://google-auth.readthedocs.io/en/stable/user-guide.html#service-account-private-key-files

    from google.oauth2 import service_account
    
    credentials = service_account.Credentials.from_service_account_file(
        '/path/to/key.json')
    
    scoped_credentials = credentials.with_scopes(
        ['https://www.googleapis.com/auth/cloud-platform'])
    

    【讨论】:

    • 或使用环境变量,即使在该页面上也是第一个选项(您只显示第二个选项)。
    猜你喜欢
    • 2019-08-25
    • 1970-01-01
    • 2020-05-21
    • 2019-04-14
    • 1970-01-01
    • 2016-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多