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 API Mọi người trong Apps Script. API này cho phép tập lệnh tạo, đọc và cập nhật dữ liệu liên hệ của người dùng đã đăng nhập, cũng như đọc dữ liệu hồ sơ của 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 về 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ụ Mọi người nâng cao sử dụng các đối tượng, phương thức và tham số giống như API công khai. Để biết thêm thông tin, hãy xem bài viết Cách xác định chữ ký phương thức.

Để báo cáo vấn đề và tìm dịch vụ hỗ trợ khác, hãy xem Hướng dẫn hỗ trợ về mọi người phiên bản 1.

Mã mẫu

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

Lấy thông tin về kết nối của người dùng

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

nâng cao/people.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 người đại diện cho người dùng

Để lấy 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ể dùng đoạn mã sau:

nâng cao/people.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);
  }
}

Yêu cầu người đó tạo Tài khoản Google

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

nâng cao/people.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);
  }
}