问题
I try to perform some operations on my Google Drive using PyDrive (and service account). This account has the right scope set in admin.google.com and in Dev's Console I've turned on both Drive API and Drive SDK.
Here's the code snippet:
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()
However, I get the following error: pydrive.files.ApiRequestError: <HttpError 403 when requesting https://www.googleapis.com/drive/v2/files?alt=json returned "Forbidden">
Why, oh why?
PS. Using the credentials provided (with a bit different scope) I can succesfully access spreadsheets (with gspread
library).
来源:https://stackoverflow.com/questions/26138528/httperror-403-forbidden-when-accessing-google-drive-using-pydrive