admin管理员组文章数量:1125039
I'm using the Graph SDK in C# to get a list of PSTN Call Logs. Some of my date ranges return over 1000 and results are on multiple pages. I'm not sure of the best way to iterate through the results in order to retrieve all records.
UPDATE: I'm able to "hack" my way through a solution but I know this is not the way to properly iterate through the pages. I set up an integer and default to 0. First time hitting it, I tell it to skip i*1000.
var response = await graphClient.Communications.CallRecords.MicrosoftGraphCallRecordsGetPstnCallsWithFromDateTimeWithToDateTime(DateTimeOffset.Parse("2024-12-18"), DateTimeOffset.Parse("2024-12-28"))
.GetAsGetPstnCallsWithFromDateTimeWithToDateTimeGetResponseAsync(requestConfiguration =>
{
requestConfiguration.QueryParameters.Skip = i * 1000;
}
);
Then I do a while loop looking for ODataNextLink and increment i.
There has to be a proper way to page through the results using the SDK but I'm not sure of how to do it. Here's the full code that I have running now and would appreciate if someone can share how to properly iterate through the results.
// Multi-tenant apps can use "common",
// single-tenant apps must use the tenant ID from the Azure portal
var tenantId = "xxx";
// Value from app registration
var clientId = "xxx";
var dotNetClientSecret = "xxx";
var tokenCredential = new ClientSecretCredential(
tenantId,
clientId,
dotNetClientSecret
);
// NOTE: Authentication requests will not go through the proxy.
// Azure.Identity token credential classes have their own separate method
// for configuring a proxy using TokenCredentialOptions.Transport
var authProvider = new AzureIdentityAuthenticationProvider(tokenCredential, null, null, isCaeEnabled: true);
var graphClient = new GraphServiceClient(authProvider);
List<Microsoft.Graph.Models.CallRecords.PstnCallLogRow> callLogs = new List<Microsoft.Graph.Models.CallRecords.PstnCallLogRow>();
int i = 0;
var response = await graphClient.Communications.CallRecords.MicrosoftGraphCallRecordsGetPstnCallsWithFromDateTimeWithToDateTime(DateTimeOffset.Parse("2024-12-18"), DateTimeOffset.Parse("2024-12-28"))
.GetAsGetPstnCallsWithFromDateTimeWithToDateTimeGetResponseAsync(requestConfiguration =>
{
requestConfiguration.QueryParameters.Skip = i * 1000;
}
);
var pstnCalls = response.Value;
var nextLink = response.OdataNextLink;
while (!string.IsNullOrEmpty(nextLink))
{
i += 1;
response = await graphClient.Communications.CallRecords.MicrosoftGraphCallRecordsGetPstnCallsWithFromDateTimeWithToDateTime(DateTimeOffset.Parse("2024-12-18"), DateTimeOffset.Parse("2024-12-28"))
.GetAsGetPstnCallsWithFromDateTimeWithToDateTimeGetResponseAsync(requestConfiguration =>
{
requestConfiguration.QueryParameters.Skip = i * 1000;
}
);
pstnCalls.AddRange(response.Value);
nextLink = response.OdataNextLink;
}
本文标签: C Graph PstnCallLogRow OdataNextLinkStack Overflow
版权声明:本文标题:C# Graph PstnCallLogRow OdataNextLink - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736653029a1946186.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论