Gists
This is a simple sample script for achieving the resumable upload to Google Drive using Axios. In order to achieve the resumable upload, at first, it is required to retrieve the location, which is the endpoint of upload. The location is included in the response headers. After the location was retrieved, the file can be uploaded to the location URL.
In this sample, a text data is uploaded with the resumable upload using a single chunk.
Gists
This is a sample script of Node.js for downloading the data and uploading the data to Google Drive with the resumable upload without saving it as a file. The downloaded data is uploaded to Google Drive with the stream.
Sample script Before you use this, please set the variables of accessToken, url, fileSize, mimeType and filename. In this case, fileSize is required to set because the data is uploaded with the resumable upload.
Gists
This is the sample scripts for creating new event with Google Meet link to Google Calendar using various languages. When I saw the official document of “Add video and phone conferences to events”, in the current stage, I can see only the sample script for Javascript. But I saw the several questions related to this for various languages. So I published the sample scripts for creating new event with Google Meet link to Google Calendar using various languages.
Gists
This is a sample script for retrieving all values from all sheets from URL of 2PACX- of Web Published Google Spreadsheet using Node.js.
In this post, it supposes that the Google Spreadsheet has already been published for Web. Ref
Before you use this sample script, please install SheetJS js-xlsx.
Flow The flow of this method is as follows.
Retrieve XLSX data from the URL of web published Google Spreadsheet as the buffer data.
Gists
These are the sample scripts for uploading files of multipart/form-data to Google Drive using Drive API with Node.js. In this case, googleapis for Node.js is not used.
In these sample script, the maximum file size is 5 MB. Please be careful this. When you want to upload the files more than 5 MB, please check this report.
Sample script 1 This sample script uploads a file using the modules of fs and request.
Gists
This is a sample script for retrieving the difference between 2 arrays, which are the old values and the new values, using Google Apps Script. In my environment, I sometimes have the situation that it is required to retrieve the difference between 2 arrays. So I prepared this as a sample script. I think that this can be also used at Javascript and Node.js. If this was also useful for your situation, I'm glad.
Updated: GetFileList for golang, Javascript, Node.js and Python
This is the libraries to retrieve the file list with the folder tree from the specific folder of own Google Drive and shared Drives.
Golang: https://github.com/tanaikech/go-getfilelist Updated to v1.0.4. Javascript: https://github.com/tanaikech/GetFileList_js Updated to v1.0.3. Node.js: https://github.com/tanaikech/node-getfilelist Updated to v1.0.5. Python: https://github.com/tanaikech/getfilelistpy Updated to v1.0.6.
node module - google-drive-getfilelist was updated to v1.0.4 v1.0.4 (May 14, 2020)
Shared drive got to be able to be used. The file list can be retrieved from both your Google Drive and the shared drive.
For example, when the folder ID in the shared Drive is used id of resource, you can retrieve the file list from the folder in the shared Drive. You can get this from https://github.
Gists
This is a simple sample script for achieving the resumable upload to Google Drive using Node.js. In order to achieve the resumable upload, at first, it is required to retrieve the location, which is the endpoint of upload. The location is included in the response headers. After the location was retrieved, the file can be uploaded to the location URL.
In this sample, a PNG file is uploaded with the resumable upload using a single chunk.
Libraries of gdoctableapp for golang, Node.js and python were updated to v1.1.0 go-gdoctableapp
v1.1.0 (January 22, 2020) 2 new methods were added. From this version, the texts can be replaced by images. The direct link and local file can be used as the image. node-gdoctableapp
v1.1.0 (January 22, 2020) New method was added. From this version, the texts can be replaced by images.
Libraries of gdoctableapp for golang, Node.js and python were updated to v1.0.5 go-gdoctableapp node-gdoctableapp gdoctableapppy Update History v1.0.5 (January 21, 2020)
When the inline objects and tables are put in the table. An error occurred. This bug was removed by this update. I got the pull request at here.
Gists
Overview This is a sample script for the music streaming player for Discord with Google Drive using Node.js.
Description This sample script can achieve to play the music when uses the voice channel on Discord. The music files are put in the specific folder of Google Drive. This script downloads all music files and plays the music files at the voice channel with the stream.
Usage 1. Register BOT to Discord At first, please register your BOT to Discord.
Gists
This is a sample script for creating a table to Google Document by retrieving values from Google Spreadsheet for Node.js.
Before you use this script, please install Node.js module of node-gdoctableapp.
$ npm install --save-dev gdoctableapp
or
$ npm install --global gdoctableapp
Sample script: This sample script uses Service Account.
In this sample script, the values are retrieved from Sheet1!A1:C5 of Spreadsheet, and new table is created to the Document using the values.
Overview This is a Node.js module to manage the tables on Google Document using Google Docs API.
Description Google Docs API has been released. When I used this API, I found that it is very difficult for me to manage the tables on Google Document using Google Docs API. Although I checked the official document, unfortunately, I thought that it's very difficult for me. So in order to easily manage the tables on Google Document, I created this library.
Gists
This is a sample Node.js script to retrieve access token from Service Account of Google without using googleapis.
const cryptor = require('crypto');
const request = require('request');
const privateKey = "###"; // private_key of JSON file retrieved by creating Service Account
const clientEmail = "###"; // client_email of JSON file retrieved by creating Service Account
const scopes = ["https://www.googleapis.com/auth/drive.readonly"]; // Sample scope
const url = "https://www.googleapis.com/oauth2/v4/token";
const header = {
alg: "RS256",
typ: "JWT",
};
const now = Math.
Gists
There are 2 sample scripts.
Create new Spreadsheet using a text value as CSV data. Overwrite the existing Google Document using a text value. When you use these script, please enable Drive API and retrieve your access token.
Create New Spreadsheet using Text Value const request = require('request');
const textData = "a1, b1, c1, d1, e1"; // This is used as CSV data.
const orgMimeType = "text/csv";
const orgFileName = "sample.
Gists
This is a sample script for executing with the synchronous process using Node.js.
Sample script function work(e) {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(e);
resolve("ok" + e);
}, 1000);
});
}
async function main() {
var ar = [1, 2, 3, 4, 5];
for (var i = 0; i < ar.length; i++) {
console.log('start' + ar[i]);
await work(ar[i]).then((res) => console.log(res));
console.log('end' + ar[i]);
}
}
main(); // Run main().
Gists
This sample script is for directly using the refreshed access token by googleapis for Node.js. When oauth2Client.refreshAccessToken((err, tokens) => {}); is used to retrieve the refreshed access token, the following error occurs.
DeprecationWarning: The refreshAccess
Token method has been deprecated, and will be removed in the 3.0 release of goo gle-auth-library. Please use the getRequestHeaders method instead.
It is required to use getRequestHeaders(). But I couldn't find the sample script using getRequestHeaders().
node module - google-drive-getfilelist was updated to v1.0.3 v1.0.3 (November 16, 2018)
Modified a bug. You can get this from https://github.com/tanaikech/node-getfilelist
You can also get this from https://www.npmjs.com/package/google-drive-getfilelist
Overview This is a Node.js module to retrieve the file list with the folder tree from the specific folder of Google Drive.
Description When I create applications for using Google Drive, I often retrieve a file list from a folder in the application. So far, I had created the script for retrieving a file list from a folder for each application. Recently, I thought that if there is the script for retrieving the file list with the folder tree from the folder of Google Drive as a module, it will be useful for me and other users.
Gists
This is a sample script for retrieving a folder tree using Node.js. In this sample, you can set the top of folder for the folder tree. In generally, the folder tree is created by retrieving folders from the top folder in order. For example, when Google Apps Script is used, the script becomes like this. But when Drive API is used for this situation, if there are a lot of folders in the top folder, a lot of APIs are required to be called.
Gists
This is a sample script for sending e-mails from gmail using Nodemailer. In order to use this, please retrieve the folloing parameters before run this script.
gmail address client ID client Secret Refresh token Please include https://mail.google.com/ in the scope. Enable gmail API at API console. Install Nodemailer const nodemailer = require('nodemailer');
var auth = {
type: 'oauth2',
user: '### your gmail address ###',
clientId: '### client ID ###',
clientSecret: '### client secret ###',
refreshToken: '### refresh token ###',
};
var mailOptions = {
from: '#####',
to: '#####',
subject: 'sample subject',
text: 'sample text',
html: '<b>sample html</b>',
};
var transporter = nodemailer.
Gists
This sample script is for downloading files under a specific folder using Node.js. It can download files with Google Docs and others.
This sample supposes as follows. So please confirm it.
quickstart is used and default quickstart works fine. In order to use this sample, please carry out as follows.
Replace listFiles() of the default quickstart to this sample. Set folderid. This script can retrieve files in the folder with folderid.
Gists
Upload contents for an item on OneDrive In order to use this script, please retrieve client id, client secret and refresh token before. About this, you can see the detail information at https://gist.github.com/tanaikech/d9674f0ead7e3320c5e3184f5d1b05cc.
1. Simple item upload This is for the simple item upload is available for items with less than 4 MB of content. The detail information is https://dev.onedrive.com/items/upload_put.htm.
var fs = require('fs');
var mime = require('mime');
var request = require('request');
var file = '.