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 một API Google Workspace. Hướng dẫn bắt đầu nhanh này sử dụng một 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, các hướng dẫn nhanh về Google Workspace sử dụng Dịch vụ nâng cao của Google để gọi 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.
/** * Print the display name if available for 10 connections. */functionlistConnectionNames(){try{/** * List the 10 connections/contacts of user * @see https://developers.google.com/people/api/rest/v1/people.connections/list */constconnections=People.People.Connections.list('people/me',{pageSize:10,personFields:'names,emailAddresses'// use other query parameter here if needed.});connections.connections.forEach((person)=>{// if contacts/connections is available, print the name of person.if(person.names && person.names.length===0){console.log('No display name found for connection.');return;}console.log(person.names[0].displayName);});}catch(err){// TODO (developer) - Handle exception from People APIconsole.log('Failed with error %s',err.message);}}
Nhấp vào biểu tượng Lưu .
Nhấp vào Dự án chưa có tên, nhập Quickstart (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 Apps Script, hãy nhấp vào Chạy.
Trong lần đầu tiên chạy mẫu, bạn sẽ được nhắc uỷ quyền 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 của 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: 2025-08-04 UTC."],[[["This quickstart demonstrates how to use Google Apps Script to access the People API and retrieve a list of connections."],["Before starting, ensure you have a Google Workspace domain with API access enabled and a Google Account with administrator privileges."],["The guide walks you through creating, configuring, and running a script that prints the display names of your connections."],["You'll need to enable the People API in your Apps Script project and authorize the script to access your Google account."],["For production environments, Google recommends reviewing authentication and authorization best practices."]]],["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"]]