如何从用户字段 LookupId 获取用户 [英] How to get user from User field LookupId

查看:25
本文介绍了如何从用户字段 LookupId 获取用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 sharepoint online 中有一个列表.在这个列表中,我有一个 person 字段.

I have a list in sharepoint online. And in this list, i have a person field.

当我调用 API 端点以获取列表中的所有项目时,我会获得人员字段的 LookupId 值.

When i call the API endpoint to get all the items in the list, i get an LookupId value for the person field.

我试图通过使用 lookupid 的值来获取用户,但它不起作用,因为无法识别 id.

I tried to get the user by using the value of the lookupid, but it don't work because the id is not recognized.

lookupid 是一个 int(例如:21)而不是一个 guid.

The lookupid is a int (eg: 21) instead of a guid.

person 字段的配置或我对 Microsoft Graph API 的调用中是否缺少某些内容?

Is there something missing in the configuration of the person field or in my calls to Microsoft Graph API ?

推荐答案

当用户首次登录 SharePoint 网站集时,会在隐藏的用户信息列表中创建 ListItem.PersonOrGroup 字段中的 LookupId 是指此列表中的 ListItem.SharePoint Online 用户信息列表的 URL 应为:

When a user signs into a SharePoint site collection for the first time, a ListItem is created in a hidden User Information List. The LookupId in a PersonOrGroup field refers to the ListItem in this list. The URL for the User Information List for SharePoint Online should be:

https://{yourTenant}.sharepoint.com/{yourSiteCollection}/_catalogs/users/detail.aspx

由于用户信息列表是通用 SharePoint 列表,您可以通过图表查询列表.首先,获取用户信息列表的列表 ID.获取列表 ID 的一种简单方法是通过 Chrome 查看用户信息站点的源并搜索listId".您应该会找到这样的结果:

Since the User Information List is a generic SharePoint list, you can query the list via Graph. First, get the list id for the User Information List. An easy way to get the list id is to view the source for the User Information Site via Chrome and search for 'listId'. You should find a result like this:

"listId":"{yourListIdIsHere}"

复制ID.通过使用复制的id、你的根站点的id和LookupId,你可以得到用户信息列表中的ListItem:

Copy the id. By using the copied id, the id of your root site and the LookupId, you can get the ListItem in the User Information List:

https://graph.microsoft.com/v1.0/sites/{siteId}/lists/{pasteCopiedListId}/item/{lookUpId}?$expand=Fields

ListItem 包含有关用户的信息,例如电子邮件,可用于识别 Azure 用户:

The ListItem contains information about the user, such as the email, which can be used to identify the Azure user:

https://graph.microsoft.com/v1.0/users/{eMail}

问题:如何从 Microsoft Graph 获取隐藏的用户信息列表?

如果您不想使用 Google Chrome 的技巧"来获取 ID,还有另一种获取站点的方法.通常,如果您想获取任何站点的 id,您可以调用:

If you do not want to use the 'trick' with Google Chrome to get the id, there is another way to get the site. Typically, if you want to get the id for any site, you would call:

https://graph.microsoft.com/v1.0/sites/{siteId}/lists

但是,即使您包含隐藏站点,您也不会找到用户信息列表的 id.我不知道为什么.另一个问题似乎是,您无法按名称过滤列表:

However, you will not find the id of the User Information List, even if you include hidden sites. I do not know why. An additional problem seems to be, that you cannot filter lists by their name:

https://graph.microsoft.com/v1.0/sites/{siteId}/lists?$filter=name eq 'users'

查询返回错误,不支持提供的过滤器语句.在不知道 id 的情况下获取列表的唯一方法似乎是使用列表的属性 displayName.但是,显示名称基于您的本地化.所以,由于我来自德国,我可以使用查询来获取该站点:

The query returns an error, that the provided filter statement is not supported. The only way to get the list without knowing the id seems to by using the property displayName of the list. However, the displayName is based on your localization. So, since I am from Germany, I can get the site by using the query:

https://graph.microsoft.com/v1.0/sites/{siteId}/lists?$filter=displayName eq 'Benutzerinformationsliste'

您需要将 Benutzerinformationsliste 替换为您的本地化名称.对于 EN,将其替换为用户信息列表".

You will need to replace Benutzerinformationsliste with your localized name. For EN replace it with 'User Information List'.

这将返回预期的结果:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites('xxx')/lists(id,name,displayName)",
    "value": [
        {
            "@odata.etag": "\"xxx\"",
            "id": "xxx",
            "name": "users",
            "displayName": "Benutzerinformationsliste"
        }
    ]
}

如您所见,列表的名称是users",那么为什么第一个过滤器语句不起作用对我来说有点神秘.也许这里有人知道并且可以提供帮助.

As you can see, the name of the list is 'users', so why the first filter statement does not work is a little mystery to me. Maybe someone here knows and can help out.

这篇关于如何从用户字段 LookupId 获取用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆