GASを試す
claspを使ってGoogle Apps Scriptを触ってみる
https://github.com/google/clasp#install
credential(~/.clasprc.json)を生成するためにログイン
clasp login
https://gyazo.com/0b96c53762518cf29331a465ce76ca19
https://kenchan0130.github.io/post/2018-12-03-1#google-apps-scriptについて
に従ってリポジトリを作る
typeが何を指すのかわからないのでデフォルトのstandaloneにする
code:zsh
$ yarn run clasp create gas-test --rootDir ./src
User has not enabled the Apps Script API. Enable it by visiting https://script.google.com/home/usersettings then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
設定からGoogle Apps Script APIをONにしておく必要があるのでした
see: https://github.com/google/clasp#install
設定後再度上記コマンドを実行。自動的にスクリプトが生成された
pull
--rootDirの設定がうまくいっておらずrootに落ちてくる
clasp.jsonに手動でrootDirを指定した
https://github.com/google/clasp#project-settings-file-claspjson
仕様が変わったのか、.gsではなく.jsでふってくる
コードを変更してpush
code:zsh
$ yarn run clasp push --watch
yarn run v1.13.0
$ /Users/kadoyau/dev/gas-test/node_modules/.bin/clasp push --watch
Watching for changed files...
Pushing files...
└─ src/Code.ts
└─ src/appsscript.json
Pushed 2 files.
プロジェクトにはコンパイル後のコードが生成されている
yarn run clasp openでプロジェクトのURLを開ける
code:code.gs
// Compiled using ts2gas 3.4.4 (TypeScript 3.7.2)
var exports = exports || {};
var module = module || { exports: exports };
function myFunction() {
var message = "kadoyau";
console.log(message);
}
ここまでで最低限のコードはかけるようになった
メールのフィルタをスプレッドシートに落とし込むコードを書いてみる
販促メールから商品を抽出
重複防止
プロジェクトページを開く
権限要求されるので許可する
https://gyazo.com/bc30a905d903e9518163bbf345e27ee1
【決定版】GAS で Gmail の検索結果をスプレッドシートに抽出する方法 - Qiita
メール検索APIを叩くとスレッドが帰ってくるので必要な情報を自前でフィルタする
Google Apps ScriptでのGmailの検索はメールではなくスレッドの検索となる | Developers.IO
GmailApp classを利用する
https://developers.google.com/apps-script/reference/gmail/gmail-app
時刻指定はどうすればいいんだろう?→queryにafter:2019/11/9 before:2019/11/12とかつける
疑問
GASでログを出力する
Script IDは公開してもいいのか(.clasp.jsonはリポジトリに含まれるべきか?)
Script IDは https://github.com/google/clasp#scriptid-required
URLがバレたくないなら公開するべきではない
パーミッションがない人は編集はできない
GASのスプレッドシートを触る
秘匿情報どうする?
プロジェクトにプロパティを設定できる。そこから取得する
https://gyazo.com/3e2e1376558aae167121f69d8faaca9c
PropertiesService.getScriptProperties().getProperty("YOUR_PROPERTY_KEY");でとれるようになる
実行5分までらしい
【Google Apps Script】5分の壁の向こう側 | canna研究所
テストがかきたい
Google Apps Script用のテストライブラリ「GASUnit」の紹介 - Qiita
課題
2019年11月11日時点でもnpmパッケージが使えない
ES Module Support · Issue #325 · google/clasp
webpackでES5に変換
参考:kenchan0130/jamf-nation-rss-gas