'Google drive image gives 403 forbidden error

I am using google drive to show images on a website. I'm using the following url to show the images:

https://drive.google.com/uc?export=view&id={fileId}

It works fine on most occasions, but some users don't see the images and get the following error message:

Failed to load resource: the server responded with a status of 403 ()

The image files and folders on the google drive are shared with everybody with a link to see. The problem does not seem browser related.

Anyone an idea how to fix this? Are there some things I forgot to do (do I need some kind of API key in the link)?



Solution 1:[1]

As of today I have the same issue. (just like a few months back when Google ended the classic sites, which I (mis)used as an image repository.)

After I cleared all cookies from the browser, the images were visible again. So that solved this problem.

If your problem persists, you should change the URL.

This URL gives a 403 err:

https://drive.google.com/uc?export=view&id={img-ID}

Change that to:

https://lh3.google.com/u/0/d/{img-ID}

For example: setting a favicon in a WebApp:

return template.evaluate()
  .setFaviconUrl('https://lh3.google.com/u/0/d/1qMrq5o54jhg5jedu9fLtzUG4dF1ijKZT1#.ico')

Solution 2:[2]

I've dealt with this problem working with Ionic Angular, in the lastest versions you should use https://lh3.google.com/u/0/d/{img-ID} as Edso said and it solves the problem. Consider that the images will only load if you have a logged google account, otherwhise the status of the response will be 302 and image will never load.

Sources

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

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 LookForAngular