我想将我的 Saas 应用程序的文件保存到我的 Google 云端硬盘帐户,我看到的所有示例都是使用 oauth2 身份验证并且需要最终用户身份验证打开浏览器,我需要从我的服务器上传文件无需任何用户交互,直接将文件发送到我的帐户!
我已经尝试了很多我在网上找到的教程,但都没有成功,主要是官方的
如何以编程方式从我的服务器进行身份验证并上传文件并使用共享文件夹等 API 功能?
我正在使用 Python,库 PyDrive使用相同的方法进行验证
最佳答案
你可以这样做,但需要使用 Service Account ,它是(或者更确切地说可以用作)应用程序的帐户,不需要浏览器打开。
文档在这里:https://developers.google.com/api-client-library/python/auth/service-accounts
还有一个示例(没有 PyDrive,它只是所有这些的包装器,但使服务帐户有点棘手):
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
from httplib2 import Http
scopes = ['https://www.googleapis.com/auth/drive.readonly']
credentials = ServiceAccountCredentials.from_json_keyfile_name('YourDownloadedFile-5ahjaosi2df2d.json', scopes)
http_auth = credentials.authorize(Http())
drive = build('drive', 'v3', http=http_auth)
request = drive.files().list().execute()
files = request.get('items', [])
for f in files:
print(f)
关于python - 来自服务器(后端)的带有 Python 的 Google Drive API,无需浏览器身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46457093/