Using service account, I`m trying to create a folder in root folder available to the account and upload images to created folder.
async def create_folder(api, parent, name):
return await api.as_service_account(
drive.files.create(
json = {
'mimeType': 'application/vnd.google-apps.folder',
'name': name,
'parents': [parent]
},
)
)
async def upload_file(api, path, parent, name):
return await api.as_service_account(
drive.files.create(
upload_file = path,
json = {
'name': name,
'parents': [parent]
},
fields = "id, name, webViewLink, webContentLink",
)
)
async def update_doc(api, id, requests):
return await api.as_service_account(
docs.documents.batchUpdate(
documentId = id,
json = {
"requests": requests
}
)
)
def insert_image(uri, index):
return {
"insertInlineImage": {
"uri": uri,
"location": {
"index": index
},
"objectSize": {
"height": {
"magnitude": 125,
"unit": "PT"
},
}
}
}
async def main(parent_id, path, file, doc_id):
async with client.api: # my "wrapper" around Aiogoogle
folder = await create_folder(
client.api,
parent_id,
"A folder in root folder"
)
image = await upload_file(
client.api,
f"{path}/{file}",
folder["id"],
"A file in created folder",
)
await update_doc(
client.api,
doc_id,
[insert_image(image["webContentLink"], 0)]
)
And while both the file and the folder were in fact created (it even says the account is the owner of them), I`m getting this error:
{'code': 400,
'message': 'Invalid requests[0].insertInlineImage: Access to the provided '
'image was forbidden.',
'status': 'INVALID_ARGUMENT'}
I tried giving these arguments to both of drive.files.create() calls:
includePermissionsForView = "published",
ignoreDefaultVisibility = True
, but no luck there