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!


Log in to reply
 

Looks like your connection to MagicMirror Forum was lost, please wait while we try to reconnect.