I am trying to get a simple Python Google Drive uploader working. I've created a project in the developer console, enabled the Drive API and added an OAuth 2.0 client ID (application type Other).
I can see the application listed in the Google Drive's Settings -> Manage Apps, and can successfully execute many operations provided by the Python Drive API client from Google. files ().insert () however fails with:
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart&convert=false&useContentAsIndexableText=false&alt=json returned "Insufficient Permission">
This is for an insert into a directory which I have made writable to everyone, as seen below:
credentials = get_credentials ()
http = credentials.authorize (httplib2.Http ())
service = discovery.build ('drive', 'v2', http=http)
PARENT_ID="0B1gLgXwTiUzlfmo0UGVsZ1NWdW1nZG9OcENNYkJua2E1d0pqWE14TjFyc2hVMHdEU1h5czQ"
perms = service.permissions().list(fileId=PARENT_ID).execute()
print ("PERMISSIONS:")
for perm in perms["items"]:
for p in perm:
print (p, perm[p])
print
parent = {
"isRoot": False,
"kind": "drive#parentReference",
"id": PARENT_ID
}
service.files ().insert (
body = {"parents" : [parent]},
media_body='./test.txt',
convert=False,
useContentAsIndexableText=False
).execute ()
Which lists the permission as:
(u'withLink', True)
(u'kind', u'drive#permission')
(u'etag', u'"F-w0rsCIWtQP8RGyv_V1DlKfcRk/icwHkDdfUYuMzqZrUsVIyvu85K8"')
(u'role', u'writer')
(u'type', u'anyone')
(u'id', u'anyoneWithLink')
(u'selfLink', u'https://www.googleapis.com/drive/v2/files/0B1gLgXwTiUzlfmo0UGVsZ1NWdW1nZG9OcENNYkJua2E1d0pqWE14TjFyc2hVMHdEU1h5czQ/permissions/anyoneWithLink')
Can anyone point me to which permission I am missing, please?
To create a folder, use the files. create method with the application/vnd. google-apps. folder MIME type and a title.
Files: insert requires authorization with at least one of the following scopes
https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/drive.appdata
https://www.googleapis.com/auth/drive.apps.readonly
Check which scope you are authenticating with.
If modifying these scopes or permissions, try deleting your previously saved credentials related file or browser cache if any.
As advised by @DalmTo, the issue was an incorrect Auth
scope in:
flow_from_clientsecrets()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With