代码之家  ›  专栏  ›  技术社区  ›  Alex Amato

使用Google Sheets API公开电子表格?

  •  3
  • Alex Amato  · 技术社区  · 7 年前

    我不知道如何使用API使电子表格对公众可见。创建或更新电子表格时,API中是否对此进行了设置?

    Google's Python Quickstart 并且能够创建和更新电子表格。

    更新:

    可以用驱动器API设置吗?

    FWIW在这里是我能够做的,以使其公开(但仍然无法将该表嵌入iframe)

    SCOPES = ['https://www.googleapis.com/auth/spreadsheets',
              'https://www.googleapis.com/auth/drive.metadata',
              'https://www.googleapis.com/auth/drive.file',
              'https://www.googleapis.com/auth/drive']
    
    drive_client = discovery.build('drive', 'v3', http=creds.authorize(Http()))
    user_permission = {
        'type': 'anyone',
        'role': 'reader',
    }
    result =drive_client.permissions().create(
        fileId=sheed_id,
        body=user_permission,
    ).execute()
    
    2 回复  |  直到 4 年前
        1
  •  3
  •   Thomas    7 年前

    权限是Google Drive的一部分,不特定于电子表格,因此您需要使用 Google Drive API 为此。请参阅 reference .

        2
  •  0
  •   Jacco Broeren    3 年前

    通过修订,可以使用google drive api发布文件。

    
    SCOPES = ['https://www.googleapis.com/auth/spreadsheets',
              'https://www.googleapis.com/auth/drive.metadata',
              'https://www.googleapis.com/auth/drive.file',
              'https://www.googleapis.com/auth/drive']
    
    drive_client = discovery.build('drive', 'v3', http=creds.authorize(Http()))
    
    drive_client.revisions().update(
        fileId=spreadSheetId,
        revisionId=1,
        body={
            "published": True,
            "publishAuto": True,
            "publishedOutsideDomain": True
        }
    ).execute()
    

    根据您想使这些设置仅在域内或域外可用,您可以相应地设置这些设置。

    裁判: https://developers.google.com/drive/api/v3/reference/revisions