Google Drive API - Automated Queries Message
Asked Answered
C

1

7

I am using this Ghost plugin to store image data on Google Drive. Recently, images have stopped loading with this error page downloaded in place of the image:

https://github.com/robincsamuel/ghost-google-drive

The site is running in a containerized Ghost instance on Google Cloud Run, source here

Do I need to open a support ticket somewhere to resolve this? Site in question is here

EDIT: Here is the code used to access the saved content.

jwtClient.authorize(function(err, tokens) {
        if (err) {
          return next(err);
        }
        const drive = google.drive({
          version: API_VERSION,
          auth: jwtClient
        });
        drive.files.get(
          {
            fileId: id
          },
          function(err, response) {
            if (!err) {
              const file = response.data;
              const newReq = https
                .request(
                  file.downloadUrl + "&access_token=" + tokens.access_token,
                  function(newRes) {
                    // Modify google headers here to cache!
                    const headers = newRes.headers;
                    headers["content-disposition"] =
                      "attachment; filename=" + file.originalFilename;
                    headers["cache-control"] = "public, max-age=1209600";
                    delete headers["expires"];

                    res.writeHead(newRes.statusCode, headers);
                    // pipe the file
                    newRes.pipe(res);
                  }
                )
                .on("error", function(err) {
                  console.log(err);
                  res.statusCode = 500;
                  res.end();
                });
              req.pipe(newReq);
            } else {
              next(err);
            }
          }
        );
      });
Clothilde answered 13/2, 2020 at 19:15 Comment(5)
Which kind of credentials is your code using to access Google Drive?Kaczmarek
It’s a service account tokenClothilde
I'm voting to close this question as off-topic because its not programming related SO cant tell you when or if you should send a support ticket to Google you should check google support pages yourself.Archduke
Using a service account is your problem. However, there are not enough details in your question on how you are creating the tokens, how you are impersonating, etc.Kaczmarek
Updated question. It's a temporary JWT token created from service account access key.Clothilde
A
2

Your problem is related to file.downloadUrl. This field is not guaranteed to work and is not supposed to be used to download files.

The correct way to do this is to use the webContentLink property instead. You can look at here for reference.

Atterbury answered 25/2, 2020 at 15:58 Comment(2)
Now I'm getting a 503 error: westmichigancopts.org/content/images/…Clothilde
Fixed the issue, PR here: github.com/robincsamuel/ghost-google-drive/pull/23Clothilde

© 2022 - 2024 — McMap. All rights reserved.