在 Microsoft Graph 中与用户一起工作Working with users in Microsoft Graph

可以使用 Microsoft Graph 构建基于用户、用户与其他用户和组的关系、用户邮件、日历和文件且有说服力的应用体验。You can use Microsoft Graph to build compelling app experiences based on users, their relationships with other users and groups, and their mail, calendar, and files.

通过 Microsoft Graph,你能以两种方式访问 用户You can access users through Microsoft Graph in two ways:

  • 通过用户 ID,/users/{id | userPrincipalName}By their ID, /users/{id | userPrincipalName}
  • 通过使用已登录的用户的 /me 别名,这与 /users/{signed-in user's id} 相同By using the /me alias for the signed-in user, which is the same as /users/{signed-in user's id}

授权Authorization

需要以下 权限 之一才能访问用户操作。用户可将前三个权限授予应用程序。其余权限只能由管理员授予应用。One of the following permissions is required to access user operations. The first three permissions can be granted to an app by a user. The rest can only be granted to an app by the administrator.

  • User.ReadBasic.AllUser.ReadBasic.All
  • User.ReadUser.Read
  • User.ReadWriteUser.ReadWrite
  • User.Read.AllUser.Read.All
  • User.ReadWrite.AllUser.ReadWrite.All
  • Directory.Read.AllDirectory.Read.All
  • Directory.ReadWrite.AllDirectory.ReadWrite.All
  • Directory.AccessAsUser.AllDirectory.AccessAsUser.All

通用属性Common properties

以下内容表示获取或列出用户时返回的属性的默认集。The following represent the default set of properties that are returned when getting a user or listing users. 这些是所有可用属性的子集。These are a subset of all available properties. 要获取更多用户属性,请使用 $select 查询参数。To get more user properties, use the $select query parameter.

属性Property 说明Description
idid 用户的唯一标识符。The unique identifier for the user.
businessPhonesbusinessPhones 用户的电话号码。The user's phone numbers.
displayNamedisplayName 用户通讯簿中显示的名称。The name displayed in the address book for the user.
givenNamegivenName 用户的名The first name of the user.
jobTitlejobTitle 用户的职务。The user's job title.
mailmail 用户的电子邮件地址。The user's email address.
mobilePhonemobilePhone 用户的手机号码。The user's cellphone number.
officeLocationofficeLocation 用户的办公地址。The user's physical office location.
preferredLanguagepreferredLanguage 用户的语言首选项。The user's language of preference.
surnamesurname 用户的姓。The last name of the user.
userPrincipalNameuserPrincipalName 用户主体名称。The user's principal name.

有关详细信息及所有属性的列表,请参阅 user 对象。For details and a list of all the properties, see the user object.

通用操作Common operations

注意: 某些操作需要其他权限。Note: Some of these operations require additional permissions.

路径Path 说明Description
/users 列出组织中的用户。Lists users in the organization.
/users/{id} 通过 ID 获取特定用户。Gets a specific user by id.
/users/{id}/photo/$value 获取用户个人资料照片。Gets the user's profile photo.
/users/{id}/manager 获取用户的经理。Gets the user's manager.
/users/{id}/messages 列出用户主收件箱中的电子邮件。Lists the user's email messages in their primary inbox.
/users/{id}/events 列出用户日历中即将发生的事件。Lists the user's upcoming events in their calendar.
/users/{id}/drive 获取用户 OneDrive 文件存储。Gets the user's OneDrive file store.
/users/{id}/memberOf 列出用户是其成员的所有组。Lists the groups that the user is a member of.