iT邦幫忙

2025 iThome 鐵人賽

DAY 4
0
佛心分享-我的私藏工具箱

告別重複瑣事: n8n workflow 自動化工作實踐系列 第 4

[Day04]_自動記錄打卡時間-#1:Google 服務憑證設定教學

  • 分享至 

  • xImage
  •  

各位是否也想記錄自己的打卡時間呢?像我每天常常會忘記自己是幾點打卡的,然後就不知道要幾點下班(?

概要

我們的目標是利用 iPhone 的「捷徑」App,判斷你接近或離開公司的地理位置時,自動觸發 n8n,將當下時間寫入指定的 Google Sheets 試算表,輕鬆完成打卡紀錄

本系列預計分 4 篇來說明,今天,我們先來完成第一步,也是最關鍵的前置作業:在 Google Cloud 中設定 n8n 所需的服務憑證

設定 Google 服務憑證

步驟一:建立 Google Cloud 專案

首先,我們需要在 Google Cloud Platform (GCP) 建立一個專案來管理相關的 API 服務

  • 請前往 Google Cloud

    https://console.cloud.google.com

  • 點選導覽列的「開啟專案挑選器」
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375E77IuUGBzx.png

  • 接著點選彈出視窗右上角的「新增專案」
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375tu0gUrWnLk.png

  • 建立專案
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375pEvmyLuL2A.png

  • 建立完成後,導覽列會彈出通知,可以從這邊點選「選取專案」來進入該專案
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375cB0cxy9H7m.png

步驟二:啟用 Google Sheets API

為了讓 n8n 能夠讀寫 Google Sheets,我們必須先啟用對應的 API

  • 再來從導覽列的搜尋找到「API 和服務」
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375dthZq4MS3H.png

  • 選擇側邊欄的「程式庫」
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375FLbBPnNfqh.png

  • 搜尋「shhet」來找到「Google Sheets API」
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375BKNOVvI80b.png

  • 點選「啟用」
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375DBPg7xVoXp.png

  • 到這邊也建議同時把我們以後可能會用到的服務一起開一開,像是「Google Drive」、「Google Doc」等等有的沒的
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375xy9XAyNbtf.png

步驟三:設定 OAuth 同意畫面與憑證

接下來,我們要設定 OAuth 同意畫面,這決定了當 n8n 請求授權時,使用者會看到的資訊

  • 回到側邊欄,找到「OAuth 同意畫面」
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375z8jdAXm1rp.png

  • 「開始」
    https://ithelp.ithome.com.tw/upload/images/20250905/201693757E2m38FlKp.png

  • 填上相關資料
    https://ithelp.ithome.com.tw/upload/images/20250905/201693753q0rcmCtyQ.png

  • 接著選擇「外部」
    https://ithelp.ithome.com.tw/upload/images/20250905/201693752DRBI4H9EZ.png

  • 同樣填寫資料
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375SEuwtYmoR5.png

  • 勾選「同意」後並點選「建立」
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375NRogGaQXW6.png

  • 點選「建立 OAuth 用戶端」
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375EX8dWH8UyE.png

  • 選擇「網頁應用程式」
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375R7DUUURHjC.png

步驟四:串接 n8n 與 Google Cloud

現在,我們要讓 n8n 和剛剛建立的 Google Cloud 憑證互相認識

  • 回到 n8n,在儀表板的右上角選擇「Create Credential」來建立憑證
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375VH6u21P6t1.png

  • 找到「Google Sheets OAuth2 API」
    https://ithelp.ithome.com.tw/upload/images/20250905/201693753HxIYEwjvi.png

  • 接著把 n8n 提供的「OAuth Redirect URL」複製起來
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375wJ7i0mlE6o.png

  • 貼回去剛剛「建立 OAuth 用戶端 ID」畫面裡面的「URI」區塊
    https://ithelp.ithome.com.tw/upload/images/20250905/201693757TYU125JZT.png

  • 建立後會提供一串 ID,請複製下來
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375NQp8mrZ7RI.png

  • 貼回去剛剛 n8n 的「Client ID」欄位
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375PSc8dB13pv.png

  • 然後「用戶端」的右上角有個「資訊與摘要」按鈕
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375A8LEd5vC1B.png

  • 點進去可以看到「用戶端密鑰」,同樣把它複製起來
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375n6cg0l1V2P.png

  • 貼到 n8n 的「Client Secret」欄位
    https://ithelp.ithome.com.tw/upload/images/20250905/201693759svy6KaFwd.png

  • 接著回到側邊欄選擇「目標對象」,底下有個「測試使用者」,點選「Add users」
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375e9KhBuTE7D.png

  • 把自己的信箱加進去並「儲存」
    https://ithelp.ithome.com.tw/upload/images/20250905/201693752EkR0Ncip1.png

  • 再來點選「發佈應用程式」
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375dGkvt6fYoD.png
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375NfANxfR8b2.png

  • 回到 n8n 點選「Sign in with Google」做驗證
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375DngNTA3vRd.png

  • 點選最底下的「前往」
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375Q3oZpMmxlW.png

  • 途中會遇到需要給的權限都打勾
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375hmoYmvG2zW.png

  • 最後看到這個畫面就代表成功囉
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375QTSrLbWx1R.png
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375Vo4Q9uQ6XZ.png

步驟五:測試流程

憑證設定好了,讓我們建立一個簡單的工作流來驗證成果吧

  • 回到 n8n 儀表板,點選右上角的「Create Workflow」來建立新的流程
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375YF7KOyCsHA.png

  • 點下畫布正中間的「Add first step」
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375P7iYczPIMO.png

  • 選擇「Trigger manually」
    https://ithelp.ithome.com.tw/upload/images/20250905/201693753ZFfnPSDXw.png

  • 下個節點選擇「Google Sheets」
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375n9MziBdgov.png

  • 選擇「Get row(s) in sheet」
    https://ithelp.ithome.com.tw/upload/images/20250905/201693756sdEfmus1i.png

  • 選個有存在的試算表
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375LZCrQe0hZW.png

  • 接著點選正下方的「Execute workflow」來測試流程
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375tRLeXEq2kI.png

  • 看到綠色輸出就代表有成功啦
    https://ithelp.ithome.com.tw/upload/images/20250905/20169375MkoR7VvsMs.png

如果一切順利,節點會顯示為綠色,並成功輸出試算表的資料
恭喜你,已經完成了最重要的第一步惹
明天我們就來測試如何從 n8n 往試算表寫入資料

官方文件

https://docs.n8n.io/integrations/builtin/credentials/google/oauth-single-service/


上一篇
[Day03]_喝水提醒小幫手
系列文
告別重複瑣事: n8n workflow 自動化工作實踐4
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言