服务帐户和 PyDrive

Dep*_*ado 5 google-apps google-drive-api pydrive

我想使用 Google Drive API 使用 cronjob 在其上存储一些备份。我只是不明白如何使用服务帐户使用 PyDrive。当我生成服务帐户文件时,我将它作为我的脚本放在目录中client_secret.json

使用此代码:

#!/usr/bin/env python
# -*- coding: utf8 -*-


from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

def main():

    gauth = GoogleAuth()
    drive = GoogleDrive(gauth)

    f = drive.CreateFile({'parent': 'toto'})
    f.SetContentFile('test.drive.py')
    f.Upload()

if __name__ == '__main__':
    main(sys.argv[1:])
Run Code Online (Sandbox Code Playgroud)

结果

pydrive.settings.InvalidConfigError: Invalid client secrets file Invalid file format.
Run Code Online (Sandbox Code Playgroud)

好吧。然后我查看了关于 SO 的其他帖子,并找到了这两个:
Automate Verification Process
The code from the first answer on this question返回:

Traceback (most recent call last):
  File "test.drive.py", line 4, in <module>
    from oauth2client.client import SignedJwtAssertionCredentials
ImportError: cannot import name SignedJwtAssertionCredentials
Run Code Online (Sandbox Code Playgroud)

然后这个:
自动化pydrive验证过程
这只是......对我没有多大帮助。

我应该从哪里开始?我该怎么办 ?有人可以给我举个 pydrive 和 Service Authentication 的例子来上传文件吗?

编辑:
经过更多研究后,似乎我需要安装pycrypto以修复上述导入错误。我不知道为什么,因为它没有在错误消息中指定。

Dep*_*ado 1

经过更多研究后,我似乎需要安装pycrypto才能修复上述导入错误。我不知道为什么,因为错误消息中没有指定。