I want to upload files to Google Drive with Google Script and Python.
I don\'t want to do this with API because it\'s with JSON file and requesting a password to goog
You can do this by publishing a web app to run as "Me"(you) with access: "Anyone, even anonymous".
function doPost(e){
const FOLDER_ID = '###FOLDER_ID###';
var name = e.parameter.name;
saveFile(e.postData.contents,name,FOLDER_ID);
return 'Success';
}
function saveFile(data,name,id) {
data = Utilities.newBlob(Utilities.base64DecodeWebSafe(data));
DriveApp.getFolderById(id)
.createFile(data.setName(name))
}
import requests, base64
url = '###WEB_APP_PUBLISHED_URL###'
name = '###FILENAME###'
requests.post(url+'?name='+name,data=base64.urlsafe_b64encode(open('##UPLOAD FILE PATH##','rb').read()))
Without letting Google know who you are by authenticating with the API key and connecting your Drive account, this is impossible.
You can follow the quickstart guide for Python authentication with the Drive REST API here. To upload files, you can use the DRIVE_SERVICE.files().create()
method in Python to upload a file to you Drive once you have gone through the authentication. The Upload file documentation can be found here.
For security reasons you can not upload files using the Drive API without first authenticating your application with your account. With the authentication code provided in the Quickstart tutorial you can authenticate your application with the https://www.googleapis.com/auth/drive.file
scope.