1

我尝试使用 PyDrive(和服务帐户)在我的 Google Drive 上执行一些操作。此帐户在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库)。

4

0 回答 0