Google Apps Script 快速入門
快速入門說明如何設定及執行呼叫 Google Workspace API 的應用程式。
Google Workspace 快速入門會使用 API 用戶端程式庫處理驗證和授權流程的部分細節。建議您為自家應用程式使用用戶端程式庫。本快速入門導覽課程會使用簡化的驗證方法,適合測試環境使用。如要使用正式環境,建議您先瞭解驗證和授權,再選擇適合應用程式的存取憑證。
建立用於向 Gmail API 提出要求的 Google Apps Script。
目標
必要條件
建立指令碼
- 前往 script.google.com/create 建立新指令碼。
- 使用下列程式碼取代指令碼編輯器的內容:
- 按一下「儲存」圖示
。
- 按一下「Untitled project」,輸入「Quickstart」,然後點選「Rename」。
啟用 Gmail API
- 開啟 Apps Script 專案。
- 按一下「編輯器」圖示 code。
- 按一下「服務」旁的「新增服務」圖示 add。
- 選取 Gmail API,然後按一下「新增」。
執行範例
在 Apps Script 編輯器中,按一下「Run」。
第一次執行範例時,系統會提示您授權存取權:
- 按一下「查看權限」。
- 選擇所需帳戶。
- 按一下「允許」。
指令碼的執行記錄會顯示在視窗底部。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-01-29 (世界標準時間)。
[null,null,["上次更新時間:2025-01-29 (世界標準時間)。"],[[["This quickstart provides instructions for creating a Google Apps Script that interacts with the Gmail API."],["It demonstrates a simplified authentication method suitable for testing, but recommends robust authentication for production environments."],["Users will learn to set up a script, enable the Gmail API, and authorize access to list their mailbox labels."],["The provided script utilizes the Gmail API client library to handle authentication and authorization flow, simplifying the process."],["For production environments, Google recommends a thorough understanding of Google Workspace authentication and authorization before implementing the script."]]],["This guide demonstrates how to use Google Apps Script to interact with the Gmail API. Key actions include creating a new script, replacing its content with provided code that lists Gmail labels, saving and renaming the script, and enabling the Gmail API in the script's services. The script is then run, requiring the user to authorize access. Successful execution results in the display of mailbox labels in the execution log.\n"]]