'Access to provided image was forbidden

Invalid requests[0].replaceImage: Access to the provided image was forbidden

I am uploading an image in the drive and trying to add it to slides using the python APIs.

Since the image needs to be publicly accessible, I am doing the following:

after upload, I am changing the permission of the image to "anyoneWithLink".

After that I try to use the link to this image in "createImage" request.

If I use the secure URL for this as shown in create image tutorial using below code,

drive_service.files().get_media(fileId=imageId).uri

I get error : "Access to the provided image was forbidden."

I get the same error if I use webContentLink, retrieved as below:

drive_service.files().get(fileId=imageId, fields="webContentLink")

If I use webViewLink instead, I get a different error as follows: "There was a problem retrieving the image. The provided image should be publicly accessible, within size limit, and in supported formats."

As I mentioned earlier, the image is already made public by changing the permissions. Are there any other steps I need to do for this to work? Also, which link should I use as url in the createImage request?

The image is 16kb png file.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source