[英]Receiving only 100 Users from Azure AD - Graph API
我們僅從以下代碼(Asp.Net Core Api)接收100 個用戶。 我們希望接收來自 Azure AD 的所有用戶。
var token = await _tokenAcquisition.GetAccessTokenForUserAsync("User.Read.All");
var client = _clientFactory.CreateClient();
client.BaseAddress = new Uri("https://graph.microsoft.com/v1.0");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var graphClient = new GraphServiceClient(client)
{
AuthenticationProvider = new DelegateAuthenticationProvider((requestMessage) =>
{
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", token);
return Task.CompletedTask;
}),
BaseUrl = "https://graph.microsoft.com/v1.0"
};
return graphClient.Users.Request().GetAsync();
MS Graph 使用分頁 output,默認頁面大小為 100 條記錄。 您已經閱讀了默認 100 個用戶的第一頁,您可以使用 top (999)
請檢查示例代碼
var users = await graphServiceClient
.Users
.Request()
.Top(999) // <- Custom page of 999 records (if you want to set it)
.GetAsync()
.ConfigureAwait(false);
while (true) {
//TODO: relevant code here (process users)
// If the page is the last one
if (users.NextPageRequest is null)
break;
// Read the next page
users = await users
.NextPageRequest
.GetAsync()
.ConfigureAwait(false);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.