Dịch vụ nhân sự nâng cao

Dịch vụ Mọi người nâng cao cho phép bạn sử dụng People API trong Apps Script. API này cho phép các tập lệnh tạo, đọc và cập nhật dữ liệu liên hệ cho người dùng đã đăng nhập và đọc dữ liệu hồ sơ cho người dùng Google.

Tài liệu tham khảo

Để biết thông tin chi tiết về dịch vụ này, hãy xem tài liệu tham khảo dành cho API Mọi người. Giống như tất cả các dịch vụ nâng cao trong Apps Script, dịch vụ Người nâng cao sử dụng cùng đối tượng, phương thức và tham số như API công khai. Để biết thêm thông tin, hãy xem phần Cách xác định chữ ký phương thức.

Để báo cáo vấn đề và tìm nguồn hỗ trợ khác, hãy xem Hướng dẫn hỗ trợ People v1.

Mã mẫu

Mã mẫu bên dưới sử dụng phiên bản 1 của API.

Lấy kết nối của người dùng

Để nhận danh sách người liên hệ trong danh bạ của người dùng, hãy sử dụng mã sau:

nâng cao/mọi người.gs
/**
 * Gets a list of people in the user's contacts.
 * @see https://developers.google.com/people/api/rest/v1/people.connections/list
 */
function getConnections() {
  try {
    // Get the list of connections/contacts of user's profile
    const people = People.People.Connections.list('people/me', {
      personFields: 'names,emailAddresses'
    });
    // Print the connections/contacts
    console.log('Connections: %s', JSON.stringify(people, null, 2));
  } catch (err) {
    // TODO (developers) - Handle exception here
    console.log('Failed to get the connection with an error %s', err.message);
  }
}

Tìm thông tin về người dùng

Để có được hồ sơ của người dùng, bạn cần yêu cầu phạm vi https://www.googleapis.com/auth/userinfo.profile bằng cách làm theo hướng dẫn thêm phạm vi rõ ràng vào tệp kê khai appsscript.json. Sau khi thêm phạm vi, bạn có thể sử dụng mã sau:

nâng cao/mọi người.gs
/**
 * Gets the own user's profile.
 * @see https://developers.google.com/people/api/rest/v1/people/getBatchGet
 */
function getSelf() {
  try {
    // Get own user's profile using People.getBatchGet() method
    const people = People.People.getBatchGet({
      resourceNames: ['people/me'],
      personFields: 'names,emailAddresses'
      // Use other query parameter here if needed
    });
    console.log('Myself: %s', JSON.stringify(people, null, 2));
  } catch (err) {
    // TODO (developer) -Handle exception
    console.log('Failed to get own profile with an error %s', err.message);
  }
}

Tìm người đó cho một Tài khoản Google

Để lấy thông tin về người đó cho bất kỳ Tài khoản Google nào, hãy sử dụng mã sau:

nâng cao/mọi người.gs
/**
 * Gets the person information for any Google Account.
 * @param {string} accountId The account ID.
 * @see https://developers.google.com/people/api/rest/v1/people/get
 */
function getAccount(accountId) {
  try {
    // Get the Account details using account ID.
    const people = People.People.get('people/' + accountId, {
      personFields: 'names,emailAddresses'
    });
    // Print the profile details of Account.
    console.log('Public Profile: %s', JSON.stringify(people, null, 2));
  } catch (err) {
    // TODO (developer) - Handle exception
    console.log('Failed to get account with an error %s', err.message);
  }
}