亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Microsoft Graph 僅返回前 100 個用戶

Microsoft Graph 僅返回前 100 個用戶

C#
皈依舞 2023-04-29 16:36:52
我有下面的代碼,它根據過濾器返回所有用戶。問題是它只返回 100 個用戶,但我知道還有更多。private List<User> GetUsersFromGraph(){    if (_graphAPIConnectionDetails == null) ReadParametersFromXML();    if (graphServiceClient == null) graphServiceClient = CreateGraphServiceClient();    var users = graphServiceClient        .Users        .Request()        .Filter(_graphAPIConnectionDetails.UserFilter)        .Select(_graphAPIConnectionDetails.UserAttributes)        .GetAsync()        .Result        .ToList<User>();    return users;}該方法僅返回 100 個用戶對象。我的 Azure 門戶管理員報告應該接近 60,000。
查看完整描述

2 回答

?
慕尼黑的夜晚無繁華

TA貢獻1864條經驗 獲得超6個贊

Microsoft Graph 中的大多數端點以頁面形式返回數據,這包括/users.


為了檢索您需要瀏覽頁面的其余結果:


private async Task<List<User>> GetUsersFromGraph()

{

    if (_graphAPIConnectionDetails == null) ReadParametersFromXML();

    if (graphServiceClient == null) graphServiceClient = CreateGraphServiceClient();


    // Create a bucket to hold the users

    List<User> users = new List<User>();


    // Get the first page

    IGraphServiceUsersCollectionPage usersPage = await graphClient

        .Users

        .Request()

        .Filter("filter string")

        .Select("property string")

        .GetAsync();


    // Add the first page of results to the user list

    users.AddRange(usersPage.CurrentPage);


    // Fetch each page and add those results to the list

    while (usersPage.NextPageRequest != null)

    {

        usersPage = await usersPage.NextPageRequest.GetAsync();

        users.AddRange(usersPage.CurrentPage);

    }


    return users;

}

這里有一個非常重要的注意事項,這種方法是從 Graph(或任何 REST API)中檢索數據的最不高效的方法。在下載所有這些數據時,您的應用程序將在那里停留很長時間。此處正確的方法是獲取每個頁面并僅處理該頁面,然后再獲取其他數據。


查看完整回答
反對 回復 2023-04-29
?
慕姐8265434

TA貢獻1813條經驗 獲得超2個贊

我有一個類似的用例,我的查詢返回值 > 100。


    final GroupCollectionPage userGroups = _appClient.users({id})

            .memberOfAsGroup()

            .buildRequest(requestOptions)

            .select("displayName,id,mail")

            .filter("startswith(displayName, 'c')")

            .orderBy("displayName")

            .get();

所以我可以輕松地遍歷結果集


    // Output each Group details

    for (Group usergroup : userGroups.getCurrentPage()) {

        System.out.println("  User Group Name: " + usergroup.displayName);

        System.out.println("  ID: " + usergroup.id);

        System.out.println(" Email: " + usergroup.mail);

    }

下面介紹如何獲取用戶組的下一頁


  public static void getGroups() {

    LinkedList<Option> requestOptions = new LinkedList<Option>();

    requestOptions.add(new HeaderOption("ConsistencyLevel", "eventual"));

    requestOptions.add(new QueryOption("$count", "true"));


    GroupCollectionPage userGroups = _appClient.users({id})

            .memberOfAsGroup()

            .buildRequest(requestOptions)

            .select("displayName,id,mail")

            .filter("startswith(displayName, 'c')")

            .orderBy("displayName")

            .get();


    List<Group> allGroupsList = new ArrayList<>();


    do {

        List<Group> currentPageGroup = userGroups.getCurrentPage();

        allGroupsList.addAll(currentPageGroup);

        GroupCollectionRequestBuilder nextPage = userGroups.getNextPage();

        userGroups = nextPage == null ? null : nextPage.buildRequest().get();

    } while (userGroups != null);


    System.out.println("Total Group count is :" + allGroupsList.size());


    for (Group usergroup : allGroupsList) {

        System.out.println("  User Group Name: " + usergroup.displayName);

        System.out.println("  ID: " + usergroup.id);

        System.out.println("  Email: " + usergroup.mail);

    }

}


查看完整回答
反對 回復 2023-04-29
  • 2 回答
  • 0 關注
  • 231 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號