V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
youthfire
V2EX  ›  问与答

通过 Google API 与账号关联的文件去向不明

  •  
  •   youthfire · 2018-12-26 23:39:04 +08:00 · 1257 次点击
    这是一个创建于 1919 天前的主题,其中的信息可能已经有所发展或是发生改变。

    正好在练习用 Python 接入 G suite 内的 Google drive,用一个 Datasheets 的库。

    https://datasheets.readthedocs.io/en/latest/index.html

    与具体账号 [email protected] 关联的 Goolge drive,通过 api 接入后,可以创建,删除,遍历所有文件与文件夹。但我发现这些都与原本就在该账号 Google drive 内的文件毫无关联。就好似一个全新的存储空间。

    即,原来 Google drive 内存在的文件,通过 api 接入后根本没有。而通过 api 新创建的文件也不会出现在浏览器可以直接访问的空间内。并不能达到我需要通过 Python 实现操作相关已存文件的目的。

    求解。

    第 1 条附言  ·  2018-12-27 17:54:18 +08:00
    目前已经可以确定是使用了 OAuth Service Account Access 造成的。如果使用 OAuth Client ID Access,则可以单独用户授权。网页选中相关账户后,点击允许授权后,页面显示“ The authentication flow has completed, you may close this window.” 关闭该页面,程序则一直运行状态中。这是因为 wa!!的关系导致了 timeout 吗?还是其他原因。
    3 条回复    2018-12-27 17:59:27 +08:00
    ronman
        1
    ronman  
       2018-12-26 23:50:48 +08:00 via Android   ❤️ 1
    估计是权限问题,我使用 rclone 连接 Google drive 时就提示我有几种权限设置:
    1 / Full access all files, excluding Application Data Folder. \ "drive"
    2 / Read-only access to file metadata and file contents. \ "drive.readonly" / Access to files created by rclone only.
    3 | These are visible in the drive website. | File authorization is revoked when the user deauthorizes the app. \ "drive.file" / Allows read and write access to the Application Data folder.
    4 | This is not visible in the drive website. \ "drive.appfolder"
    / Allows read-only access to file metadata but 5 | does not allow any access to read or download file content. \ "drive.metadata.readonly"

    第四种就和你描述的类似,网页端不可见。建议阅读以下官方 API 说明
    youthfire
        2
    youthfire  
    OP
       2018-12-27 00:22:41 +08:00
    @ronman 谢谢提供的思路

    在 Stackoverflow 看到如下:

    You appear to be authenticating using a service account. You need to remember that a service account is not you, think of it as a dummy user it has its own Google drive account. You have been uploading files to the service accounts Google drive account. You can do a files.list to see these uploaded files. There is no web interface view for a service account.

    You can take the service account email address and share a directory on your personal google drive account this will give the service account permissions to upload to this directory. You will need to remember to have the service account patch the files to grant your user access to the files or you wont have any permissions on them.

    对于 OAuth 2.0 client IDs 和 Service account keys 这两个 key 的关系,仍然有点傻傻分不清楚。
    youthfire
        3
    youthfire  
    OP
       2018-12-27 17:59:27 +08:00
    目前已经可以确定是使用了 OAuth Service Account Access 造成的。如果使用 OAuth Client ID Access,则可以单独用户授权。网页选中相关账户后,点击允许授权后,页面显示“ The authentication flow has completed, you may close this window.” 关闭该页面,程序则一直运行状态中。这是因为 wa!!的关系导致了 timeout 吗?还是其他原因。
    看日志里有
    FileNotFoundError: [Errno 2] No such file or directory: '/Users/noname/.datasheets/client_credentials.json'
    ConnectionResetError(54, 'Connection reset by peer'))


    Google 的 API 中心里只有 client_secret.json 和 service_key.json,没有额外 client_credentials.json 可以下载了啊?
    Python 程序连接也必须用这段语句吗?
    #socket.socket = socks.socksocket
    #socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 1086)

    我加入这段语句,在 OAuth Service Account Access 情况下程序是正常的。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5721 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 06:09 · PVG 14:09 · LAX 23:09 · JFK 02:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.