# Google App Script 課程計畫 ###### tags: `課程` ## 課程資訊 * 日期/時間:2023/05/02 Tue. 19:00~21:00 * 講師:yuchen * 難易度:易,需有程式基礎 ## 課前準備 * Google Account * 免費版(@gmail.com)即可 * 需可使用雲端硬碟功能之帳號 * 不能是家庭帳號下的孩童帳號 * VScode * 或相對應文字編輯器 * 需可編寫html、JS * 可使用vscode.dev代替 * Line Account * 登入Line Notify網站使用 ## 課程大綱 * (25min) Google App Script簡介 * 歷史、用途 * (10min) 一些語法介紹 * (25min) 實作一:新回覆通知 * 表單+GAS+Line Notify * (25min) 實作二:公佈欄系統 * 表單+GAS+JS * (25min) 實作三:資料查詢 * 試算表+GAS+JS --- ``` 以下是課程大致內容 ``` --- ## Google App Script 簡介 ### What is Google App Script(以下簡稱GAS) * 來自Google的說明: ```! Google Apps Script 是速度飛快的應用程式開發平台,可讓您輕鬆地建立與Google Workspace整合的商業應用程式。您在新式 JavaScript 中編寫程式碼,並可存取 Gmail、日曆、雲端硬碟等常用 Google Workspace 應用程式。無須安裝任何程式碼,直接在瀏覽器中提供程式碼編輯器,並讓指令碼在 Google 伺服器上執行。 * REF: https://developers.google.com/apps-script/overview ``` ### 用途 * 類似VBA (Visual Basic for Applications) * 界接Google服務(ex.試算表、表單...etc)與外部功能 * 外部可以透過GAS來讀、寫、更動在Google服務中的東西 * 有點抽象 * 舉例來說就是如果我今天想要用Sheets來當作簡易資料庫 * 懶、方便,但缺點就是當資料筆數極多時候,查詢或寫入的動作會非常慢,因為他只是一張表,並沒有經過正規化 * 便可以透過GAS分別去撰寫查詢和寫入的語法 * 讓外部應用程式可以成功界接到Sheets * 方法很多 * POST、GET * URL代值 ### 優點 * 快速部屬 * 搭配Google服務建立自動化流程 * Serverless * 初學者易懂 * ~~免費的真香~~ ### 缺點 * 免費版限制 * 但正常使用狀況下,不太會撞到限制 * 常用的URL Fetch calls,每日可以使用(呼叫)20,000次 * 需要有一定的程式基礎(JavaScript) * 運行速度慢 * 每次運行的時間最多只有6分鐘 * 有一些漏洞 ### 簡易Demo #### 簡易request&response 1. 先測試下列程式,部屬成網頁應用程式並透過網址存取後,會出現甚麼結果 ```javascript= function doGet() { return "Hi, this is response from Google App script"; } ``` :::warning 在這個code中,利用網址存取時,會得到"指令碼已完成,但傳回值的類型不是支援的傳回類型。" 在查閱官方文件後你可以看到  所以若我們想要讓他直接在網頁上顯示出文字,則我們需要將他轉換為HTML或Content ::: 2. 現在測試下面這個程式 ```javascript= function doGet() { return ContentService.createTextOutput("Hi, this is response from Google App script"); } ``` 你便會發現,網頁上以文字方式顯示出我們所指定的文字了 3. 經過以上的測試,這就便是我們對網址進行request(GET Mode),而網頁回傳給我們一個respone ## 進階用法 ### 搭配Line Notify、Telegram Bot ### 搭配HTML Code ## Reference * [Offical Document](https://developers.google.com/apps-script/guides/dashboard) * [Google App Script到底是什麼? - Medium](https://medium.com/@dustfantasy/google-app-script-%E5%88%B0%E5%BA%95%E6%98%AF%E4%BB%80%E9%BA%BC-6a37a06a85a8) * [Google Apps Script 介紹 - 育將電腦工作室](https://www.ugm.com.tw/modules/tad_book3/page.php?tbsn=104&tbdsn=1741) * [利用Google App Script 實作Telegram Bot - ithome](https://ithelp.ithome.com.tw/articles/10239939)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up