All Projects → vitogit → Gdrivesync.js

vitogit / Gdrivesync.js

Licence: mit
Javascript wrapper library for Google Drive API v3

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Gdrivesync.js

drive
Google Drive client for the commandline
Stars: ✭ 6,470 (+6782.98%)
Mutual labels:  sync, google-drive
Drivesync
Google Drive synchronization for Linux
Stars: ✭ 148 (+57.45%)
Mutual labels:  sync, google-drive
synchly
Automate database backups with customizable recurring schedules.
Stars: ✭ 27 (-71.28%)
Mutual labels:  sync, google-drive
Remotestorage.js
⬡ JavaScript client library for integrating remoteStorage in apps
Stars: ✭ 2,155 (+2192.55%)
Mutual labels:  sync, javascript-library
Rclone
"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Yandex Files
Stars: ✭ 30,541 (+32390.43%)
Mutual labels:  sync, google-drive
Aws S3
S3Client - A Javascript Library for AWS S3 File Upload
Stars: ✭ 79 (-15.96%)
Mutual labels:  javascript-library
Canal mysql nosql sync
基于canal 的 mysql 与 redis/memcached/mongodb 的 nosql 数据实时同步方案 案例 demo canal client
Stars: ✭ 1,254 (+1234.04%)
Mutual labels:  sync
Ditherjs
A javascript library which dithers an <img> using a fixed palette
Stars: ✭ 76 (-19.15%)
Mutual labels:  javascript-library
Vuex Multi Tab State
💾🔗🖥️ Share, synchronize and persist state between multiple tabs with this plugin for Vuex. TypeScript types included.
Stars: ✭ 77 (-18.09%)
Mutual labels:  sync
Plexdrive
Plexdrive mounts your Google Drive FUSE filesystem (optimized for media playback)
Stars: ✭ 1,324 (+1308.51%)
Mutual labels:  google-drive
Password Leak
A library to check for compromised passwords
Stars: ✭ 92 (-2.13%)
Mutual labels:  javascript-library
Ssim
🖼🔬 JavaScript Image Comparison
Stars: ✭ 83 (-11.7%)
Mutual labels:  javascript-library
Akubra
Simple solution to keep a independent S3 storages in sync
Stars: ✭ 79 (-15.96%)
Mutual labels:  sync
Zifi
zifi - Make Stories everywhere using React 😍
Stars: ✭ 87 (-7.45%)
Mutual labels:  javascript-library
Etebase Rs
A Rust client library for Etebase
Stars: ✭ 78 (-17.02%)
Mutual labels:  sync
Create Google Shared Drive
Cloudflare Redesigned Script for creating a Shared/Team Drive
Stars: ✭ 93 (-1.06%)
Mutual labels:  google-drive
Iroha Javascript
JavaScript library for Iroha, a Distributed Ledger Technology (blockchain) platform.
Stars: ✭ 77 (-18.09%)
Mutual labels:  javascript-library
Vault
Easy persistence of Contentful data for Android over SQLite.
Stars: ✭ 80 (-14.89%)
Mutual labels:  sync
Crowdin Cli
A command-line client for the Crowdin API
Stars: ✭ 89 (-5.32%)
Mutual labels:  sync
Railschat
Real-time Rails-based Webchat for Instant Messaging (实时Web聊天室)
Stars: ✭ 81 (-13.83%)
Mutual labels:  sync

gDriveSync.js

Javascript wrapper library for Google Drive API v3.

It authenticate, save, load and list documents from your google drive.

Install : Adding the library

Simple download the lib

Download the files in the lib folder: login.service.js and drive.service.js. Add them to your app, for instance:

<script src="../lib/login.service.js"></script>
<script src="../lib/drive.service.js"></script>

Bower

  bower install gdrive-sync-js --save

Then import the library

<script src="../bower_components/lib/login.service.js"></script>
<script src=".../bower_components/lib/drive.service.js"></script>

Npm

  npm install gdrive-sync-js --save

Then import the library

  <script src="../node_modules/gdrive-sync-js/lib/login.service.js"></script>
  <script src="../node_modules/gdrive-sync-js/lib/drive.service.js"></script>

How to use it

After the lib is loaded you can use the new service like this

      var SCOPES = 'https://www.googleapis.com/auth/drive.file'
      var CLIENT_ID = 'YOUR CLIENT ID';
      DISCOVERY_DOCS = ['https://www.googleapis.com/discovery/v1/apis/drive/v3/rest'];
      window.loginService = new LoginService(CLIENT_ID, SCOPES, DISCOVERY_DOCS);
  • SCOPES: scopes to request, as a space-delimited string.
  • CLIENT_ID: The app's client ID, found and created in the Google Developers Console.
  • DISCOVERY_DOCS: are the apis that we are going to use. An array of discovery doc URLs or discovery doc JSON objects.

For more info check the Demo

File Explorer Demo (list folders and files)

Screen Shot 2020-03-11 at 4 31 14 PM

Add your api client_id to demo/fileExplorer/index.html. You can get the client id following the instruction from step1 here https://developers.google.com/drive/v3/web/quickstart/js

Clone, install and run

npm install
npm start // to run the dev server

Then go to http://localhost:4000/demo/fileExplorer

It will ask for signin using a google account, or automatically signin if you already authorized the app.

This demo list the folders and files from your root folder ordered by type and name. If you click in a folder it will open it and also will show in "selected resources" the folder id. If you select a file it will show you the file id.

Barebones Save Google doc Demo (list, save, load documents)

Screen Shot 2020-03-11 at 4 40 17 PM

Add your api client_id to demo/index.html. You can get the client id following the instruction from step1 here https://developers.google.com/drive/v3/web/quickstart/js

Clone, install and run

npm install
npm start // to run the dev server

Then go to http://localhost:4000/demo

The demo uses jQuery but just for hide/show stuff, is not needed.

It will ask for signin using a google account, or automatically signin if you already authorized the app.

Write something and click save, it will create a file in your google drive called gDriveSync.example.txt.

If you change the text and save it again, it will update the file. Have in mind that if you refresh the page the doc id reference will be lost so if you save again it will create a new document.

The document has a mimeType of application/vnd.google-apps.document' this is a google doc, so you can open and edit it from google drive.

API methods

  • login.service.js (parameters: CLIENT_ID, and SCOPES)

    • initClient: Silently check to see if a user has already authorized the app. Pass a callback function and it will return true/false if user is signin/signoff
    • signIn: promp the accounts selector to signin.
    • signOut: sign out the current user.
    • userProfile: return an object with logged user information and you can call: getId() getName(), getEmail()
  • drive.service.js

    • saveFileRaw: It creates a new raw file without mimetype, or update an existing one if the file has an ID (parameter file) If the file object specified the parents parameter (array of folders ids) it will save the file in that specific folder. Useful to save json files. Save it as file.json

    • loadFileRaw: It loads a file given an ID. (parameter file)

    • saveFile: It creates a new google document (application/vnd.google-apps.document), or update an existing one if the file has an ID (parameter file) If the file object specified the parents parameter (array of folders ids) it will save the file in that specific folder.

    • loadFile: It loads a google document as text (plain/text) given an ID. (parameter file)

    • list: It return the files (id and name) from Google Drive (parameters: resource and callback function). resource= {query_name:'', parents:'', mimeType:'', trashed:false}

      • listFiles: It return the files (id and name) from Google Drive that contains the query_name. (parameters: query_name and callback function)
      • listFilesAt: It return the files (id and name) from Google Drive that contains the query_name and are at a specific folder (parents parameter). (parameters: query_name, parents and callback function)
      • listFolders: It return the folders (id and name) from Google Drive that contains the query_name. (parameters: query_name and callback function)
      • listFoldersAt: It return the folders (id and name) from Google Drive that contains the query_name and are at a specific folder (parents parameter). (parameters: query_name, parents and callback function)

    A file is just an object like

    var file = {id: null, name: 'testName', content:'hello' , parents:['folderId']}
    

    A resource is just an object like

    var resource = {query_name:'file_name', parents:'folderId', mimeType:'plain/text' ,trashed:false , orderBy: 'name'}
    

    This is used to pass options to the list method.

    • trashed: boolean value, true to show just files that are in the trash. false to not show them. not set to show everything.
    • orderBy: A comma-separated list of sort keys. Valid keys are 'createdTime', 'folder', 'modifiedByMeTime', 'modifiedTime', 'name', 'quotaBytesUsed', 'recency', 'sharedWithMeTime', 'starred', and 'viewedByMeTime'. Each key sorts ascending by default, but may be reversed with the 'desc' modifier.

    More info: https://developers.google.com/drive/v3/reference/files/list

Changelog

v0.3.7

  • Update lightserver library and update readme

v0.3.5

  • Add load and save raw mode. Useful for json files

v0.3.3

  • Add fileExplorer Demo

v0.3.2

  • Add orderBy option to list files

v0.3.1

  • Add trashed option to just list files and folders that are not in the trash bin.
  • listFiles, listFilesAt, listFolders and list FoldersAt don´t show trashed files by default.

v0.3.0

  • Published to npm and bower
  • Updated readme with steps to install it using npm and bower

v0.2.0

  • Add generic list method to list files and folders using parameters: query_name (name contains query_name), parents (specific folder to look), mimeType
  • Add helper methods to make it easy to list files (listFilesAt,listFiles) and folders(listFoldersAt, listFolders).
  • Save file to specific folder: Pass parents:['folderId'] to the file object when doing saveFile. This will add the file named filename.txt to the specific folder with folderId
  var file = {name: 'filename.txt', parents:['folderId'], content:'hello'};
  driveService.saveFile(file, function(savedFile){
    console.log('saved file with id:'+savedFile.id)
  })

Info

This is not intended to use in a production environment, it just for educational purposes.

The library code is based on this example https://github.com/googledrive/web-quickeditor but using the Google Drive api v3 and plain Javascript.*

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].