高级人员服务
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
通过高级 People 服务,您可以在 Apps 脚本中使用 People API。此 API 允许脚本创建、读取和更新已登录用户的联系人数据,以及读取 Google 用户的个人资料数据。
参考
如需详细了解此服务,请参阅 People API 的参考文档。与 Apps 脚本中的所有高级服务一样,高级 People 服务使用的对象、方法和参数均与公共 API 相同。如需了解详情,请参阅方法签名是如何确定的。
如需报告问题并寻求其他支持,请参阅“People v1”支持指南。
示例代码
以下示例代码使用 API 的版本 1。
获取用户的连接
如需获取用户通讯录中的联系人列表,请使用以下代码:
获取用户的个人信息
如需获取用户个人资料,您需要按照有关向 appsscript.json
清单文件添加明确范围的说明,请求 https://www.googleapis.com/auth/userinfo.profile
范围。添加相应范围后,您可以使用以下代码:
获取 Google 账号的联系人
如需获取任何 Google 账号的个人信息,请使用以下代码:
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThe advanced People service in Apps Script utilizes the People API to manage contact data for the logged-in user and access Google user profiles.\u003c/p\u003e\n"],["\u003cp\u003eThis advanced service needs to be enabled before use and mirrors the functionality of the public People API.\u003c/p\u003e\n"],["\u003cp\u003eScripts can create, read, and update contact details for the current user, as well as retrieve profile information for other Google users.\u003c/p\u003e\n"],["\u003cp\u003eSample code snippets are provided to demonstrate functionalities like fetching user connections, retrieving the user's own profile, and getting information for any Google Account by ID.\u003c/p\u003e\n"]]],[],null,["# Advanced People Service\n\nThe advanced People service allows you to use the\n[People API](/people) in Apps Script. This API allows scripts\nto create, read, and update contact data for the logged in user and read profile\ndata for google users.\n| **Note:** This is an advanced service that must be [enabled before use](/apps-script/guides/services/advanced).\n\nReference\n---------\n\nFor detailed information on this service, see the\n[reference documentation](/people/api/rest) for the People API.\nLike all advanced services in Apps Script, the advanced People service uses the\nsame objects, methods, and parameters as the public API. For more information, see [How method signatures are determined](/apps-script/guides/services/advanced#how_method_signatures_are_determined).\n\nTo report issues and find other support, see the\n[People v1 support guide](/people/support).\n\nSample code\n-----------\n\nThe sample code below uses [version 1](/people/api/rest) of the API.\n\n### Get the user's connections\n\nTo [get a list of people in the user's contacts](/people/api/rest/v1/people.connections/list),\nuse the following code: \nadvanced/people.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/people.gs) \n\n```javascript\n/**\n * Gets a list of people in the user's contacts.\n * @see https://developers.google.com/people/api/rest/v1/people.connections/list\n */\nfunction getConnections() {\n try {\n // Get the list of connections/contacts of user's profile\n const people = People.People.Connections.list('people/me', {\n personFields: 'names,emailAddresses'\n });\n // Print the connections/contacts\n console.log('Connections: %s', JSON.stringify(people, null, 2));\n } catch (err) {\n // TODO (developers) - Handle exception here\n console.log('Failed to get the connection with an error %s', err.message);\n }\n}\n```\n\n### Get the person for the user\n\nTo [get the user's profile](/people/api/rest/v1/people/get), you need to request\nthe `https://www.googleapis.com/auth/userinfo.profile` scope by following the\n[instructions to add explicit scopes](/apps-script/concepts/scopes#setting_explicit_scopes)\nto your `appsscript.json` manifest file. Once the scope is added, you can use\nthe following code: \nadvanced/people.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/people.gs) \n\n```javascript\n/**\n * Gets the own user's profile.\n * @see https://developers.google.com/people/api/rest/v1/people/getBatchGet\n */\nfunction getSelf() {\n try {\n // Get own user's profile using People.getBatchGet() method\n const people = People.People.getBatchGet({\n resourceNames: ['people/me'],\n personFields: 'names,emailAddresses'\n // Use other query parameter here if needed\n });\n console.log('Myself: %s', JSON.stringify(people, null, 2));\n } catch (err) {\n // TODO (developer) -Handle exception\n console.log('Failed to get own profile with an error %s', err.message);\n }\n}\n```\n\n### Get the person for a Google Account\n\nTo [get the person information for any Google Account](/people/api/rest/v1/people/get),\nuse the following code: \nadvanced/people.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/people.gs) \n\n```javascript\n/**\n * Gets the person information for any Google Account.\n * @param {string} accountId The account ID.\n * @see https://developers.google.com/people/api/rest/v1/people/get\n */\nfunction getAccount(accountId) {\n try {\n // Get the Account details using account ID.\n const people = People.People.get('people/' + accountId, {\n personFields: 'names,emailAddresses'\n });\n // Print the profile details of Account.\n console.log('Public Profile: %s', JSON.stringify(people, null, 2));\n } catch (err) {\n // TODO (developer) - Handle exception\n console.log('Failed to get account with an error %s', err.message);\n }\n}\n```"]]