1

PyDrive (およびサービス アカウント) を使用して、Google ドライブでいくつかの操作を実行しようとしています。このアカウントにはadmin.google.comで適切な範囲が設定されており、開発者のコ​​ンソールで 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