gdrive-simple
An intuitive and object-oriented wrapper on the Google Drive API. Exposes File and Folder objects which have Promise-based asynchronous functions. Also includes a simple utility for managing signed-in state.
Check out the source code here.
Example usage
import gds from "gdrive-simple";
gds.init({
clientId: "YOUR CLIENT ID",
scopes: [
"https://www.googleapis.com/auth/drive.appdata",
"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/drive",
],
}).then(() => {
gds.listenForSignInChange(handleSignedInChange);
});
function handleSignedInChange(isSignedIn) {
if (!isSignedIn) {
document.getElementById("signIn").onclick = gds.signIn;
} else {
const root = gds.getRootFolder();
const appdata = gds.getAppDataFolder();
root.listFiles().then(files => {
console.log("Files in the user's Drive:", files);
});
appdata.getFile("myfile.json")
.then(file => file.write( {thisIsSome:"json"} ))
.then(() => console.log("myfile.json succesfully written."));
appdata.getFolder("myfolder")
.then(folder => folder.getFile("myfileinmyfolder.json"))
.then(file => file.read())
.then(contents => console.log("Contents:", contents));
}
}
License
gdrive-simple
is licensed under the MIT License. However, Google's JavaScript client library, which this library depends upon, is licensed under an Apache License, so please take care to also comply with the terms for that library.