正好在练习用 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
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 说明 |
2
youthfire OP @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 的关系,仍然有点傻傻分不清楚。 |
3
youthfire OP 目前已经可以确定是使用了 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 情况下程序是正常的。 |