MagicMirror² v2.5.0 is available! For more information about this release, check out this topic.

Exporting a file from Google Drive with specific mimeType



  • Working on a module to retrieve and display a Google Drive document, in response to my musings here. The module is meant to export and display a shared Google Doc on MM as a shared whiteboard among many users; it will update whenever the file is updated.

    I blatantly stole much of the Google Drive implementation from MMM-GTasks (is there another Google Drive implementation for MM?), which itself is lifted mostly from Google’s Drive API quickstart.

    However, the actual fetch of the file is (still) causing me difficulty.

    Here’s the code:

    var drive = google.drive({
      version: 'v2',
      auth: this.gauth
    });
    
    drive.files.export({
      fileId: "MY_FILE_ID",
      mimeType: "text/html",
      alt: "media"
    }, function (err, buffer) {
      if (err) {
        console.log('The API returned an error: ' + err);
        callback(err);
        return;
      } else {
        callback(response);
      }
    });
    

    However, the API complains that I’m not providing a mimeType:

    The API returned an error: Error: Required parameter: mimeType
    { Error: Required parameter: mimeType
        at RequestError.Error (native)
        ...
      code: 400,
      errors: 
       [ { domain: 'global',
           reason: 'required',
           message: 'Required parameter: mimeType',
           locationType: 'parameter',
           location: 'mimeType' } ] }
    

    I know the request is authenticating (I can list files) and I have full access (i.e. “https://www.googleapis.com/auth/drive”). I can retrieve the metadata for the file, but cannot specify the mimeType for a response (or for that matter, specify the file contents with alt: 'media'). According to the API docs, “text/html” is a valid MIME type.

    Wondering if anyone can spot an error or propose a workaround. I might revert to a simpler GET request as I don’t need many of the googleapis features, but it would be nice to have implemented properly.

    Haven’t created an initial repo as I don’t have it working yet. Thanks!



  • Hi ninja 🙂
    I have come to same problem as you 2 months ago, did you solve the Error: Required parameter: mimeType?

    Thanks in advance for your reply 😉





  • @luckylooke Great news, is it up and working? Sorry, I never got mine working, but may now try again. Thanks!



  • Anyone interested… here is the code which worked for me: https://github.com/google/google-api-nodejs-client/issues/1098