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

2018-12-26 23:39:04 +08:00
 youthfire

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

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

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

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

求解。

1262 次点击
所在节点    问与答
3 条回复
ronman
2018-12-26 23:50:48 +08:00
估计是权限问题,我使用 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
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
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 情况下程序是正常的。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/521346

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX