我尝试使用PyDrive(和服务帐户)在我的Google云端硬盘上执行某些操作。此帐户在 admin.google.com 中设置了正确的范围,在Dev的控制台中,我已启用了Drive API和Drive SDK。
以下是代码段:
credentials = SignedJwtAssertionCredentials(
service_account_name, #...@developer.gserviceaccount.com
key, # from file
scope, # https://www.googleapis.com/auth/drive
sub='...' # user
)
gauth = GoogleAuth()
gauth.credentials = credentials
gauth.Authorize()
drive = GoogleDrive(gauth)
file1 = drive.CreateFile({'title': 'Hello.txt'})
file1.Upload()
但是,我收到以下错误:pydrive.files.ApiRequestError: <HttpError 403 when requesting https://www.googleapis.com/drive/v2/files?alt=json returned "Forbidden">
为什么,为什么?
PS。使用提供的凭据(范围有点不同),我可以成功访问电子表格(使用gspread
库)。