htmlgoogle-apps-scripthttp-status-code-403

Status code 403 opening a drive's image with google apps script


I'm working to an image gallery, the image's names and id are in a google spreadsheet, the script read the spreadsheet and dynamically publish the images. At the begin it worked fine, now i have a status code 403.

To debug the problem I have hardcoded a single image in a very simple test script

This is "Code.gs"

function doGet(request) {
  var htmlTemplate=HtmlService.createTemplateFromFile("prova");
  return htmlTemplate.evaluate();
}

This is "prova.html"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <title></title>
</head>
<body>
   xxxxxxxxxxxxxxxxxxxxxx
   <img src="https://drive.google.com/uc?export=view&id=11CakSm75WDYnpfd_Qs2LlYoVmJwdAmUR" alt="sample" />
  </div>
</body>
</html>

This is the header from the error:

Stato:              403
Versione:           HTTP/2
Trasferito:         1,39 kB (dim. 0 B)
Referrer Policy:    strict-origin-when-cross-origin
Priorità richiesta: Low
Risoluzione DNS:    Sistema

This is the link at the debug script

The script reply with code 403, but the direct link to the image works fine!

I can't understand how to resolve the problem.

Thanks for any help!


Solution

  • I finally found the correct syntax for the link. Not by my own, but in the Philippe reply to this question, who had the hint from this response. The trick is:

    > https://lh3.googleusercontent.com/d/[image id]
    

    instead of

    > https://drive.google.com/uc?export=view&id=[image id]
    

    Hope it can help.