使用python gspread删除使用client.del_spreadsheet()的电子表格

发布于 2025-02-13 18:28:38 字数 866 浏览 0 评论 0原文

删除由API服务帐户创建的表的最简单方法是什么?使用GSPREAD API,我能够创建一张工作表,然后作为编辑分享给自己。现在我无法删除,因为我不是所有者。

    name = 'mysheet'
    gc = gspread.service_account(filename=path_to_credentials)

    try:
        spreadsheet = gc.open(name)
    except gspread.SpreadsheetNotFound:
        spreadsheet = gc.create(name)
        sharewith = '[email protected]'
        spreadsheet.share(sharewith, perm_type='user',
                          notify=True, role='editor')

我想重复使用服务帐户凭据,但是我很难考虑如何在Google OAuth对象中获得适合与gspread.client()一起使用的凭据。下面类似于我的想法,但我觉得我缺少一些东西。

    oa = gspread.oauth(credentials_filename=path_to_credentials)
    c = gspread.Client(auth=oa)
    c.del_spreadsheet('<spreadsheetId>')

如果有人可以提供见解,我会听。

What is the easiest way to delete a sheet created by an API service account? Using the gspread API, I was able to create a sheet, and then share back to myself as editor. Now I can't delete because I am not the owner.

    name = 'mysheet'
    gc = gspread.service_account(filename=path_to_credentials)

    try:
        spreadsheet = gc.open(name)
    except gspread.SpreadsheetNotFound:
        spreadsheet = gc.create(name)
        sharewith = '[email protected]'
        spreadsheet.share(sharewith, perm_type='user',
                          notify=True, role='editor')

I want to reuse the service account credentials, but I am having trouble thinking about how to get the credentials in a Google OAuth object suitable to use with gspread.Client(). Below kind of resembles what I am thinking, but I feel I am missing something.

    oa = gspread.oauth(credentials_filename=path_to_credentials)
    c = gspread.Client(auth=oa)
    c.del_spreadsheet('<spreadsheetId>')

If anyone has insights to offer, I would listen.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文