GoogleAPITips

Using Google API Client Library (gapi) for JavaScript with Service Account

Gists This is a sample script for using Google API Client Library (gapi) for JavaScript with the service account. Unfortunately, in the current stage, gapi cannot directly use the service account. So, in this case, it is required to implement the script for retrieving the access token from the service account. In this report, I would like to introduce the method for using gapi with the service account using a Javascript library.

Specification of Search Query for File List Method in Drive API

Gists In this report, I would like to report about the current specification of the search query for the file list method in Drive API. Recently, I noticed that the specification of the search query for the file list method in Drive API might have been changed. I thought that to know the change of specification of the search query is important for creating the application using Drive API. In this report, I would like to introduce the current specification of the search query.

Simple Script of Resumable Upload with Google Drive API for Axios

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.

Downloading and Uploading File to Google Drive without Saving File with Stream and Resumable Upload using Node.js

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.

Updated: GetFileList for golang, Javascript, Node.js and Python

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.

Updated: node module - google-drive-getfilelist

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.

Simple Script of Resumable Upload with Google Drive API for Python

Gists This is a simple sample script for achieving the resumable upload to Google Drive using Python. 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.

Simple Script of Resumable Upload with Google Drive API for Node.js

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.

Creating a Table to Google Document by Retrieving Values from Google Spreadsheet for Node.js

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.

node module - node-gdoctableapp

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.

Directly Using Access Token by googleapis for Node.js

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

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.

Create Folder Tree of Google Drive using Node.js

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.

Send mails from Gmail using Nodemailer

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.

Updating Thumbnail of File on Google Drive using Python

Gists This sample script is for updating thumbnail of file on Google Drive using Python. This sample supposes that quickstart is used and default quickstart works fine. In order to use this sample, please carry out as follows. Replace main() of the default quickstart to this sample. Script : import base64 # This is used for this sample. def main(): credentials = get_credentials() http = credentials.authorize(httplib2.Http()) service = discovery.

Downloading Files Under Specific Folder using Node.js

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.

Interconversion Between Google Docs and Microsoft Docs

Gists This sample script is for the interconversion between Google Docs (document, spreadsheet and presentation) and Microsoft Docs (word, excel and powerpoint). The feature is to convert them without Advanced Google Services. Since Advanced Google Services is not used for this, if you publish your script with this script, you are not necessary to explain how to install Advanced Google Services. This script converts between Google Docs and Microsoft Docs using UrlFetchApp.

Downloading Shared Files on Google Drive Using Curl

Gists When the shared files on Google Drive is downloaded, it is necessary to change the download method by the file size. The boundary of file size when the method is changed is about 40MB. File size < 40MB CURL filename="### filename ###" fileid="### file ID ###" curl -L -o ${filename} "https://drive.google.com/uc?export=download&id=${fileid}" File size > 40MB When it tries to download the file with more than 40MB, Google says to download from following URL.

Retrieving HTML File ID from Microsoft Docx File on Google Drive

This sample script converts from Microsoft Docx File on Google Drive to Google Spreadsheet, and converts to HTML file. Drive APIs v2 and v3 are used for this. Please set as follows. Drive API v2 Drive API v3 “Drive API v2” can be used at Google Apps Script by enabling Drive API of Advanced Google services and of Google API Console. How to use it is as follows.

File Transfer for Google Drive Without Authorization

Overview In this article, I would like to introduce how to transfer files for Google Drive under no authorization. This has also been published here. https://github.com/tanaikech/FileTransfer Description When we download and upload files for Google Drive, it usually has to use Drive API. In order to use Drive API, access token is required. If you want to make your friends download and upload files for your Google Drive, the authorization process is to take time.

OCR using Google Drive API

This is a sample script for OCR using Google Drive API. A text file which converted by OCR can be retrieved by inputting an image file. In this sample, Python Quickstart is used. The detail information is https://developers.google.com/drive/v3/web/quickstart/python. Please read “Step 1: Turn on the Drive API” and “Step 2: Install the Google Client Library”. from __future__ import print_function import httplib2 import os import io from apiclient import discovery from oauth2client import client from oauth2client import tools from oauth2client.

Converting PDF to TXT

This is a sample script for converting a PDF file to a TXT file. 2 steps are required for this. Upload a PDF file as a Google Document Download a Google Document as a TXT file In this sample, Python Quickstart is used. The detail information is https://developers.google.com/drive/v3/web/quickstart/python. Please read “Step 1: Turn on the Drive API” and “Step 2: Install the Google Client Library”. from __future__ import print_function import httplib2 import os import io from apiclient import discovery from oauth2client import client from oauth2client import tools from oauth2client.

How to use "fields" of Drive APIs

There are a lot of APIs on Google. When we use Google Drive APIs, they usually have “fields” as a resource. The parameter “fields” gives various information which is selected to us. This is one of important parameters. And this can be used at Google Apps Script (GAS) although that version is v2. About how to use it, there are some documents. But it is difficult to find how to use it at GAS.

Download Files Without Authorization From Google Drive

Overview In this article, files can be downloaded without authorization. Description When we download files from Google Drive, it usually has to use Drive API. In order to use Drive API, access token is required. If you want to make your friends download files from your Google Drive, the authorization process is to take time. Also Web Link for each files can be used. But it has to set for each files.

Retrieving Access Token for Google Drive API using GAS

These GASs retrieve an access token for using Google Drive API. There are 3 parts. Before you use this, please retrieve client ID, client secret and redirect uri from Google , and choose scopes. 1. Retrieving code from web This is a script to output URL for retrieving “code” from web. Please retrieve “code” by import this URL to your browser. After you run this script, using “url” got from this script, it retrieves “code”.

File Upload and Download with File Convert For curl using Drive API

It is necessary to retrieve access token on Google. Scope is as follows. https://www.googleapis.com/auth/drive Other mimetypes can be seen here. Download and convert from Spreadsheet to Excel curl -X GET -sSL \ -H "Authorization: Bearer [Your access token]" \ -o "Excel file name" \ "https://www.googleapis.com/drive/v3/files/[File ID]/export?mimeType=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" Upload and convert from Excel to Spreadsheet curl -X POST -sSL \ -H "Authorization: Bearer [Your access token]" \ -F "metadata={ \ name : '[File name on Google Drive]', \ mimeType : 'application/vnd.