MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Exporting a file from Google Drive with specific mimeType

    Scheduled Pinned Locked Moved Development
    5 Posts 2 Posters 5.1k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • N Offline
      ninjabreadman
      last edited by ninjabreadman

      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!

      Problem with config or JavaScript? Copy/paste it into JSHint.
      Check out the detailed walkthroughs on install, config, modules, etc.

      1 Reply Last reply Reply Quote 0
      • L Offline
        luckylooke
        last edited by

        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 ;)

        N 1 Reply Last reply Reply Quote 0
        • L Offline
          luckylooke
          last edited by

          Finnaly I was able to fix it… here is more info: https://stackoverflow.com/questions/49447186/exporting-file-from-google-drive-using-googleapi-in-node-js

          1 Reply Last reply Reply Quote 1
          • N Offline
            ninjabreadman @luckylooke
            last edited by

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

            Problem with config or JavaScript? Copy/paste it into JSHint.
            Check out the detailed walkthroughs on install, config, modules, etc.

            1 Reply Last reply Reply Quote 0
            • L Offline
              luckylooke
              last edited by

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

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Enjoying MagicMirror? Please consider a donation!
              MagicMirror created by Michael Teeuw.
              Forum managed by Sam, technical setup by Karsten.
              This forum is using NodeBB as its core | Contributors
              Contact | Privacy Policy