Phần bắt đầu nhanh giải thích cách thiết lập và chạy một ứng dụng gọi API Google Workspace.
Các hướng dẫn nhanh về Google Workspace sử dụng thư viện ứng dụng API để xử lý một số thông tin chi tiết về quy trình xác thực và uỷ quyền. Bạn nên sử dụng thư viện ứng dụng cho các ứng dụng của riêng mình. Phần bắt đầu nhanh này sử dụng phương pháp xác thực đơn giản phù hợp với môi trường thử nghiệm. Đối với môi trường phát hành công khai, bạn nên tìm hiểu về quy trình xác thực và uỷ quyền trước khi chọn thông tin xác thực truy cập phù hợp với ứng dụng của mình.
/** * Lists the user's tasks. * @see https://developers.google.com/tasks/reference/rest/v1/tasklists/list */functionlistTaskLists(){constoptionalArgs={maxResults:10};try{// Returns all the authenticated user's task lists.constresponse=Tasks.Tasklists.list(optionalArgs);consttaskLists=response.items;// Print task list of user if available.if(!taskLists||taskLists.length===0){console.log('Notasklistsfound.');return;}for(consttaskListoftaskLists){console.log('%s(%s)',taskList.title,taskList.id);}}catch(err){// TODO (developer) - Handle exception from Task APIconsole.log('Failedwitherror%s',err.message);}}
Nhấp vào biểu tượng Lưu .
Nhấp vào Untitled project (Dự án chưa có tên), nhập Quickstart (Bắt đầu nhanh) rồi nhấp vào Rename (Đổi tên).
Định cấu hình tập lệnh
Bật API Google Tasks
Mở dự án Apps Script.
Nhấp vào biểu tượng Trình chỉnh sửacode.
Bên cạnh Dịch vụ, hãy nhấp vào biểu tượng Thêm dịch vụ
add .
Chọn Tasks API rồi nhấp vào Thêm.
Chạy mẫu
Trong trình chỉnh sửa Apps Script, hãy nhấp vào Run (Chạy).
Trong lần đầu chạy mẫu, bạn sẽ được nhắc uỷ quyền truy cập:
Nhấp vào Xem lại quyền.
Chọn một tài khoản.
Nhấp vào Cho phép.
Nhật ký thực thi của tập lệnh sẽ xuất hiện ở cuối cửa sổ.
[null,null,["Cập nhật lần gần đây nhất: 2024-12-21 UTC."],[[["This quickstart demonstrates how to create a Google Apps Script that interacts with the Google Tasks API to list tasks."],["Before running the script, you need a Google account with Google Tasks and Drive enabled, and you will need to enable the Google Tasks API within the script."],["The script utilizes Google API client libraries for authentication and is designed for a testing environment; production environments require more robust authentication."],["After configuring and running the script, it will prompt for authorization to access your Google Tasks data and then display your task lists in the execution log."],["For more advanced usage and troubleshooting, refer to the provided links for Google Apps Script, authentication, and the Tasks API."]]],["This content details how to create and run a Google Apps Script that interacts with the Google Tasks API. Key actions include creating a new script, replacing the default code with a provided sample to list task lists, saving and renaming the script, and enabling the Tasks API within the script's services. Running the script requires authorizing access, after which it will display the user's task lists in the execution log, or error if failed. It use a simplified authorization and suggest to do more in depth authorization for production.\n"]]