简体   繁体   English

Microsoft Graph API - 获取 Sharepoint 文档库中的项目列表时超时 (C# ASP DotNet)

[英]Microsoft Graph API - Timeout while getting list of items in Sharepoint Document Library (C# ASP DotNet)

I'm using Microsoft Graph API to get a list of documents in a Sharepoint Document Library.我正在使用 Microsoft Graph API 获取 Sharepoint 文档库中的文档列表。 Code was fine for 6 months.代码可以使用 6 个月。 Last Friday my code broke.上周五我的密码坏了。

There are about 700 documents in the library, and in the past the request would complete after 5-6 seconds.库中大约有 700 个文档,过去请求会在 5-6 秒后完成。 As of last Friday (23/09/2022) it started timing out after (~120 seconds).截至上周五(2022 年 9 月 23 日),它开始超时(约 120 秒)。 If I limit it to 200 rows, it works after 12 seconds, but I need all 700, If there is a way to do paging that could work.如果我将它限制为 200 行,它会在 12 秒后工作,但我需要所有 700 行,如果有一种方法可以进行分页。 then I could make my own method.然后我可以制定自己的方法。 Also if I could increase the timeout it might work - I have tried modifying both the GraphClient.HttpProvider.OverallTimeout and the request,WithMaxRetry to 900 seconds.另外,如果我可以增加超时时间,它可能会起作用——我尝试将 GraphClient.HttpProvider.OverallTimeout 和请求 WithMaxRetry 修改为 900 秒。 but it still times out after around 122 seconds.但它仍然在大约 122 秒后超时。

Here is the relevant part of my code (rowLimit is an int set to 5000):这是我的代码的相关部分(rowLimit 是一个设置为 5000 的整数):

List<QueryOption> queryOptions = new List<QueryOption>()
            {
                new QueryOption("Top", $"{rowLimit}"),
                new QueryOption ("Prefer","allowthrottleablequeries")
            };

IDriveItemChildrenCollectionPage result = await GraphClient.Sites[siteID].Drives[documentLibraryID].Root.Children
                    .Request(queryOptions)
                    .Expand("listItem")
                    .WithMaxRetry(1) //set 1 max retry and set timeout
                    .WithMaxRetry(TimeSpan.FromSeconds(900)
                    .GetAsync();

After ~122 seconds I receive the following exception: Code: tooManyRetries Message: More than 1 retries encountered while sending the request. ~122 秒后,我收到以下异常:代码:tooManyRetries 消息:发送请求时重试次数超过 1 次。

As mentioned, I can get it to work if I limit the number of rows - 200 rows return in around 12 seconds, 400 rows return in around 24 seconds.如前所述,如果我限制行数,我可以让它工作——200 行在大约 12 秒内返回,400 行在大约 24 秒内返回。 The strange thing is it was fine last week, so perhaps Microsoft changed something?奇怪的是上周还不错,所以也许微软改变了什么?

I managed to work around my issue by using pagination:我设法通过使用分页来解决我的问题:

List<DriveItem> allItems = new();

var result = await GraphClient.Sites[siteID].Drives[documentLibraryID].Root.Children
                .Request()
                .Expand("listItem")
                .Top(100)
                .GetAsync();

            var pageIterator = PageIterator<DriveItem>
                .CreatePageIterator(
                    GraphClient,
                    result,
                    (item) =>
                    {
                        allItems.Add(item);
                        return true;
                    });

            await pageIterator.IterateAsync();

This way I get the results 100 at a time, which was within the timeout threshold.这样我一次得到 100 个结果,这在超时阈值内。 They are then all added to a List (allItems) so I didn't need to change the rest of my code.然后将它们全部添加到列表 (allItems) 中,因此我不需要更改代码的 rest。

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

相关问题 使用Sharepoint文档库和Microsoft Graph API处理Excel文件 - Work with Excel file using Sharepoint document library with Microsoft Graph API 使用 Microsoft.Graph 库 c# 从 Sharepoint 列表中获取日期字段 - Get date field from Sharepoint list using Microsoft.Graph library c# 在 C# 中通过 Microsoft Graph API 在 Microsoft 团队通用频道中发布消息时出现禁止访问错误 - Getting Forbidden error while posting the message in Microsoft teams general channel via Microsoft Graph API in C# C# 从 SharePoint 2013 文档库中检索文档列表 - C# Retrieve Document List From SharePoint 2013 Document Library 使用C#获取SharePoint文档库位置 - Getting SharePoint document library location using C# sharepoint 2013 使用列表模板 C# 创建文档库 - sharepoint 2013 create document library using List Template C# C# - Microsoft Graph API - 从自定义列表中获取图片 - C# - Microsoft Graph API - Getting Pictures from Customlist Sharepoint 带图表的列表项值 API - Sharepoint List Items values with Graph API 无法从 C# 和图形资源管理器中的 Sharepoint 图形获取驱动器项目和驱动器文件夹 - Failing to getting Drive items and Drive Folders from Sharepoint Graph in C# and Graph Explorer 使用 Microsoft Graph 将 C# Asp.Net Core 中的文件上传到 Sharepoint/OneDrive,无需用户交互 - Upload a file in C# Asp.Net Core to Sharepoint/OneDrive using Microsoft Graph without user interaction
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM