Hướng dẫ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. Tài liệu 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 kiểm thử. Đối với môi trường phát hành công khai, bạn nên tìm hiểu về
xác thực và uỷ quyền
trước khi
chọn thông tin đăng nhập để truy cập
phù hợp với ứng dụng của bạn.
Trong Apps Script, hướng dẫn bắt đầu nhanh về Google Workspace sử dụng Dịch vụ nâng cao của Google để gọi các API Google Workspace và xử lý một số thông tin chi tiết về quy trình xác thực và uỷ quyền.
Mục tiêu
Định cấu hình môi trường.
Tạo và định cấu hình tập lệnh.
Chạy tập lệnh.
Điều kiện tiên quyết
Một miền Google Workspace đã bật quyền truy cập vào API.
Một Tài khoản Google có đặc quyền của quản trị viên trong miền đó.
Quyền truy cập vào Google Drive
Tạo tập lệnh
Tạo một tập lệnh mới trong trình chỉnh sửa Apps Script bằng cách truy cập vào script.google.com/create.
Thay thế nội dung của trình chỉnh sửa tập lệnh bằng đoạn mã sau:
/** * @typedef {Object} EmailAddress * @see https://developers.google.com/people/api/rest/v1/people#Person * @property {string} value * Note: This is a partial definition. *//** * @typedef {Object} Name * @see https://developers.google.com/people/api/rest/v1/people#Person * @property {string} displayName * Note: This is a partial definition. *//** * @typedef {Object} Person * @see https://developers.google.com/people/api/rest/v1/people#Person * @property {Name[]} names * @property {EmailAddress[]} [emailAddresses] * Note: This is a partial definition. *//** * @typedef {Object} Connection * @see https://developers.google.com/people/api/rest/v1/people.connections/list * @property {Person[]} connections * Note: This is a partial definition. *//** * Print the display name if available for 10 connections. */functionlistConnectionNames(){// Use the People API to list the connections of the logged in user.// See: https://developers.google.com/people/api/rest/v1/people.connections/listif(!People||!People.People||!People.People.Connections){thrownewError("People service not enabled.");}constconnections=People.People.Connections.list("people/me",{pageSize:10,personFields:"names,emailAddresses",});if(!connections.connections){console.log("No connections found.");return;}for(constpersonofconnections.connections){if(person.names&&
person.names.length > 0&&
person.names[0].displayName){console.log(person.names[0].displayName);}else{console.log("No display name found for connection.");}}}
Nhấp vào biểu tượng Lưu .
Nhấp vào Dự án không có tiêu đề, nhập
Hướng dẫn bắt đầu nhanh rồi nhấp vào Đổi tên.
Định cấu hình tập lệnh
Bật People API
Mở dự án Apps Script.
Nhấp vào 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
People API
rồi nhấp vào Thêm.
Chạy mẫu
Trong trình chỉnh sửa tập lệnh Apps Script, hãy nhấp vào Chạy.
Lần đầu tiên bạn chạy mẫu, hệ thống sẽ nhắc bạn cho phép truy cập:
Nhấp vào Xem xét quyền.
Chọn một tài khoản.
Nhấp vào Cho phép.
Nhật ký thực thi tập lệnh sẽ xuất hiện ở cuối cửa sổ.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2026-04-23 UTC."],[],["This document guides users to create and run a Google Apps Script that interacts with the People API. It involves configuring a new script on `script.google.com`, replacing the script editor's content with provided code, saving, and renaming the project. Users must enable the People API as a service within the script and authorize access during the initial run. The script then lists the display names of 10 connections. Production environments need appropriate authentication credentials.\n"]]