简体   繁体   English

尝试使用Sharepoint和Microsoft Graph API获取通用列表的所有记录

[英]Trying to get all records of a generic list using Sharepoint and Microsoft Graph api

When trying to get records of a list in SharePoint i keep getting Response like: 当尝试在SharePoint中获取列表的记录时,我一直在收到类似的响应:

{"@odata.context":"https://graph.microsoft.com/beta/$metadata#users('123')/sharepoint/sites('456')/lists('789')/items","value":[]}

I was able to run through all sites and lists but still fail on items. 我能够遍历所有站点和列表,但在项目上仍然失败。 The list has the GenericList template. 该列表具有GenericList模板。 However on another list with the template DesignCatalog i were able to get all items. 但是在模板DesignCatalog的另一个列表中,我能够获取所有项目。 Is "/items" the wrong way to get records of a generic list? “ / items”是获取通用列表记录的错误方法吗?

Here is a snippet of my current Code: 这是我当前代码的摘要:

            const string serviceEndpoint = "https://graph.microsoft.com/beta/";

            HttpClient client = new HttpClient();
            var token = await _authenticationHelper.GetTokenAsync();
            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);

            // get the site
            HttpResponseMessage responseGetSites = await client.GetAsync(new Uri(serviceEndpoint + "sharePoint:/Intranet"));
            if (responseGetSites.IsSuccessStatusCode)
            {
                string responseContent = await responseGetSites.Content.ReadAsStringAsync();
                var jResult = JObject.Parse(responseContent);
                siteItem = JsonConvert.DeserializeObject<SiteItemModel>(jResult.ToString());

                // get all lists with the given site id
                HttpResponseMessage responseGetLists = await client.GetAsync(new Uri(serviceEndpoint + "sharepoint/sites/" + siteItem.SiteId + "/lists"));
                if (responseGetLists.IsSuccessStatusCode)
                {
                    string responseContent2 = await responseGetLists.Content.ReadAsStringAsync();
                    var jResult2 = JObject.Parse(responseContent2);

                    foreach (JObject listresponse in jResult2["value"])
                    {
                        ListItemModel desiralizedItemModel = JsonConvert.DeserializeObject<ListItemModel>(listresponse.ToString());
                        listItemCollection.Add(desiralizedItemModel);
                    }

                    // find a specific list
                    string listId = listItemCollection.Where(w => w.listName == "MyTestlist").First().listId;

                    // get all records with of the given list
                    HttpResponseMessage responseGetItems = await client.GetAsync(new Uri(serviceEndpoint + "sharepoint/sites/" + siteItem.SiteId + "/lists/" + listId + "/items"));
                    if (responseGetItems.IsSuccessStatusCode)
                    {
                        string responseContent3 = await responseGetItems.Content.ReadAsStringAsync();
                        var jResult3 = JObject.Parse(responseContent3);

I had the same problem. 我有同样的问题。 I had to add "Sites.ReadWrite.All" permission under MS Graph, not under sharepoint (I was writing to the list as well, but "Sites.Read.All" should work). 我必须在MS Graph下(而不是在共享点下)添加“ Sites.ReadWrite.All”权限(我也在向列表中写入内容,但“ Sites.Read.All”应该可以工作)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试使用Sharepoint和Microsoft Graph api获取配置文件信息 - Trying to get profile info using Sharepoint and Microsoft Graph api 尝试使用Microsoft Graph api搜索Sharepoint文件 - Trying to search Sharepoint files using Microsoft Graph api Microsoft graph Api 获取 sharepoint 列表项,使用查询 $filter=indexOf 或 $search 未找到项 - Microsoft graph Api get sharepoint list items, found no item using query $filter=indexOf or $search 如何使用 microsoft graph 列出所有个人 sharepoint 站点? - How to list all personal sharepoint sites using microsoft graph? 如何使用microsoft graph api获取sharepoint中的列(字段) - How to get columns(fields) in sharepoint using microsoft graph api 使用Microsoft Graph API获取SharePoint文件夹和文档 - Get SharePoint folders and docs using Microsoft Graph API 使用microsoft graph api获取sharepoint日历事件的重复数据? - Get recurrence data of sharepoint calendar events using microsoft graph api? 如何使用 Microsoft Graph 获取 SharePoint 在线组 API - How to get SharePoint online Groups using Microsoft Graph API 使用 Microsoft Graph API 从 SharePoint 在线获取文件 - Get a file from SharePoint Online using Microsoft Graph API Microsoft Graph API - Sharepoint 列表无法调用创建/更新 SharePoint 列表项,GET/DELETE 有效 - Microsoft Graph API - Sharepoint list unable to call create/update SharePoint list items, GET/DELETE works
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM