小编Ric*_*ard的帖子

为 Google 服务帐户电子邮件创建别名?

我已经与我的 Google 服务帐户电子邮件共享了一个 Google 表格,它看起来像:

myappname-service@myappname-266229.iam.gserviceaccount.com

这允许我的应用程序访问该 Google 表格。

我希望能够使用别名为丑陋的自动生成的服务帐户电子邮件 ( myappname-service@myappname-266229.iam.gserviceaccount.com)的自定义电子邮件地址(例如 google@myappname.com)共享 Google 表格。

我怎么能去做这件事?

编辑:

用于与 Google API 交互的代码示例

from google_auth_httplib2 import AuthorizedHttp
from google.oauth2 import service_account
import pygsheets

def _get_gc():
    scope = ['https://www.googleapis.com/auth/spreadsheets']
    credentials = service_account.Credentials.from_service_account_file(
        settings.GOOGLE_SERVICE_AUTH_FILE,
        scopes=scope,
    )
    http = AuthorizedHttp(credentials, http=HTTP)
    logger.info('Created GC creds, returning...')
    return pygsheets.authorize(custom_credentials=credentials, http=http)


def do_something(url):
    gc = _get_gc()
    spreadsheet = gc.open_by_url(url)

Run Code Online (Sandbox Code Playgroud)

google-authentication google-sheets google-cloud-iam

5
推荐指数
1
解决办法
381
查看次数