gdc
google-drive-client-api
npm i google-drive-client-api
gdc

google-drive-client-api

is a very small library to upload / download / delete or modify files on goole drive.

by manuel3108

0.1.1 (see all)License:ISCTypeScript:Not FoundCategories:Vanilla JavaScript Google Drive API
npm i google-drive-client-api
Readme

google drive client api

is a very small library to upload / download / delete or modify files on goole drive.

IMPORTATNT: Currently only works for application-appdata folder, because it was such a mess to get here that I didn't wanted to continue. But feel free to PR, should be an easy fix

installation

npm install google-drive-client-api

usage

import drive from 'google-drive-client-api'

function load() {
    // CLIENT_ID is an id you will need to get through the google developer console
    // DISCOVERY_DOCS is an array [], can be empty in most cases
    // SCOPES list of scopes seperated by spaces, propably one of those: https://www.googleapis.com/auth/drive.appdata or https://www.googleapis.com/auth/drive.appdata or https://www.googleapis.com/auth/drive.file
    drive.load("CLIENT_ID", DISCOVERY_DOCS, "SCOPES").then(() => {
        console.log("google client loaded");
    });
}

function isLoggedIn() {
    if(drive.isLoggedIn()) {
        console.log("user is logged in");
    } else {
        console.log("user is NOT logged in");
    }
}

function login() {
    drive.login().then(() => {
        console.log("login successfull");
    })
}

function create() {
    drive.create("test-file.json").then((data) => {
        // file created

        // the id of the file is in fileId
        let fileId = data.result.id;
        
        // push some content into the file
        drive.update(fileId, "Test-Content")
    });
}

function list() {
    drive.list().then((data) => {
        // all files where you have access to
        let files = data.result.files;
        
        // download the content of each file
        files.forEach(file => {
            drive.download(file.id).then((data) => {
                file.content = data.body;
            })
        });
    });
}

function deleteFile(id) {
    drive.delete(id).then(() => {
        // deletet file with given id
    });
}

example

  • clone this repo
  • cd example
  • npm install
  • npm run dev

Downloads/wk

8

GitHub Stars

0
No data available

LAST COMMIT

NaNyrs ago

MAINTAINERS

1

CONTRIBUTORS

0

OPEN ISSUES

0

OPEN PRs

0
No data available
VersionTagPublished
0.1.1
latest
2yrs ago
No tutorials found
Add a tutorial