Google Apps Script to Download Files From Google Drive Without Authorization Using Python in Command Line Full Project For Beginners

 

 

Usage

1. Deploy Web Apps

  1. Open the Script Editor.
  2. On the Script Editor
    • File -> Manage Versions -> Save New Version
    • Publish -> Deploy as Web App
    • At Execute the app as, select “your account”
    • At Who has access to the app, select “Anyone, even anonymous”
    • Click “Deploy”
    • Copy “Current web app URL”
    • Click “OK”

2. Paste following script on Script Editor.

function doPost(e) {
  return (function(id){
    var file = DriveApp.getFileById(id);
    return ContentService
          .createTextOutput(JSON.stringify({
            result: file.getBlob().getBytes(),
            name: file.getName(),
            mimeType: file.getBlob().getContentType()
          }))
          .setMimeType(ContentService.MimeType.JSON);
  })(e.parameters.id);
}

3. At local pc, use following script.

import numpy as np
import requests
r = requests.post(
    "https://script.google.com/macros/s/### Your ID ###/exec",
    data={"id": "### File ID ###"}
)
f = open(r.json()["name"], "bw")
f.write(np.array(r.json()["result"], dtype=np.uint8))
f.close()
print("Filename = {0}, MimeType = {1}".format(r.json()["name"], r.json()["mimeType"]))

Leave a Reply