|
Import csv files to specified google spreadsheet automatically
MIT
- node version 14 or later
git clone git@github.com:codeforjapan/gspreadsheet-importer.git
cd gspreadsheet-importerclasp login will open browser and ask your permissions.
yarn install
clasp login
clasp create [YOUR_PROJECT_NAME] --type standalone # select `standalone` if you need to selectIf you don't have permission of using App Script API, you will see below message.
Error: Permission denied. Enable the Apps Script API:
https://script.google.com/home/usersettingsOpen the URL and allow the permission.
Open .clasp.json and copy scriptID value, then delete appscript.json.
Copy .clasp.json.sample to .clasp.json and replace the YOUR_SCRIPT_ID by the copied scriptId.
rm appsscript.json
cp .clasp.json.sample .clasp.json # overwrite file
vi .clasp.jsonPush latest code. Please answer y to confirmation of overwriting manifest.
% clasp push
? Manifest file has been updated. Do you want to push and overwrite? Yes
└─ src/Code.ts
└─ src/appsscript.json
Pushed 2 files.Goto Google Cloud Platform Console and create new project.
Please find Google Drive API from search box and enable it.
Then copy Project number and Project ID. (You will use Project ID later).
Open GAS page by executing clasp open and set the copied Project number by selecting the menu Resources -> Cloud Platform Project
Paste the copied project ID and press Set Project button.
If you do this first time the system shows link to creating OAuth consent screen. Please create it from the shown link. (Internal user type is OK. Just set application name and save.)
After that, back to the google apps script page and press Set Project button again.
You will see below message. Now you can close this window.
Then, please set the previously copied Project ID by running clasp apis list.
% clasp apis list
Open this link: https://script.google.com/d/.../edit
Go to *Resource > Cloud Platform Project...* and copy your projectId
(including "project-id-")
? What is your GCP projectId? [ENTER YOUR ID]Then create credential
clasp open --credsThe command will open new browser, then please create new credential of OAuth client ID by+CREATE CREDENTIALS link, The application type should be Desktop App, any name is OK.
After creating the credential, please download the credential data, then locate it as .cred.json at this project root holder.
mv ~/Downloads/client_secret_xxxxxx.apps.googleusercontent.com.json ./.cred.jsonThen login using the credential file. Below command will open browser to allow permissions again.
clasp login --creds .creds.jsonOpen GAS window and publish the script as a web api from publish -> Deploy as web app.
clasp openGet deployment ID by running clasp deployments and copy the ID of web app meta-version.
% clasp deployments
2 Deployments.
- AKfycbw8ryblmM3eNxe0_...... @HEAD
- AKfycbw3395mg1mABA1YS...... @1 - web app meta-version # ← Copy this IDThen craete .env file for the deployment
echo 'DEPLOYMENT_ID="[THE_DEPLOYMENT_ID]"' > .envYou can initialize this script by running init function.
% clasp run init # it will require
Running in dev mode.
No response.It will create new drive named gspreadsheet-importer on your root drive.
You can run GAS function by using clasp run.
Please run test function by running this command.
clasp run testThis will import csv file from this site: https://mynumbercard.code4japan.org/ .
Please open your drive and confirm the files are imported. You can get Google Drive URL by blow command:
% clasp run getInitialDriveID
Running in dev mode.
https://drive.google.com/drive/folders/1WdDDE.....Please implement sync() method in the Code.ts file.
You can run this function by running clasp run sync.
If you changed the script and wants to apply the changes, please run:
make push







