2017-03-07 228 views
0

我正在嘗試使用以下代碼段從Azure Active Directory獲取用戶組中的信息。無法從Azure Active Directory獲取用戶組

public async Task<List<string>> GetUserGroupsAsync(string alias) 
{ 
      var groupList = new List<string>(); 
      try 
      { 
       Microsoft.Azure.ActiveDirectory.GraphClient.IUser userObject = getUserObject(alias); 
       Task t = Task.Run(async() => 
       { 
        var grouppages = await ((IUserFetcher)userObject).MemberOf.OfType<Microsoft.Azure.ActiveDirectory.GraphClient.Group>().ExecuteAsync(); 
        do 
        { 
         groupList.AddRange(grouppages.CurrentPage.Select(g => g.Mail != null ? g.Mail.Trim() : null).Where(eMail => !string.IsNullOrWhiteSpace(eMail)).ToList()); 
         grouppages = await grouppages.GetNextPageAsync(); 
        } while (grouppages != null); 
       }); 
       t.Wait(); 
      } 
      catch 
      { 
       throw; 
      } 
      return groupList; 
} 

問題:我收到例外低於一些用戶。

System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> Microsoft.Data.OData.ODataErrorException: The specified page token value has expired and can no longer be included in your request. ---> System.Data.Services.Client.DataServiceQueryException: An error occurred while processing this request. ---> System.Data.Services.Client.DataServiceClientException: {"odata.error":{"code":"Directory_ExpiredPageToken","message":{"lang":"en","value":"The specified page token value has expired and can no longer be included in your request."}}} 
    at System.Data.Services.Client.BaseAsyncResult.EndExecute[T](Object source, String method, IAsyncResult asyncResult) 
    at System.Data.Services.Client.QueryResult.EndExecuteQuery[TElement](Object source, String method, IAsyncResult asyncResult) 
    --- End of inner exception stack trace --- 
    at System.Data.Services.Client.QueryResult.EndExecuteQuery[TElement](Object source, String method, IAsyncResult asyncResult) 
    at System.Data.Services.Client.DataServiceRequest.EndExecute[TElement](Object source, DataServiceContext context, String method, IAsyncResult asyncResult) 
    at System.Data.Services.Client.DataServiceContext.EndExecute[TElement](IAsyncResult asyncResult) 
    at Microsoft.Azure.ActiveDirectory.GraphClient.Extensions.DataServiceContextWrapper.<ExecuteAsync>b__6b[TSource,TInterface](IAsyncResult i) 
    at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization) 

請幫忙解決這個問題。這將是非常有益的。

+0

錯誤信息不夠明顯嗎?您的訪問令牌已過期。順便說一句,你應該包括'getUserObject'函數 –

回答

0

根據我的理解,當我們試圖逐頁檢索組的成員時,會發生異常(The specified page token value has expired and can no longer be included in your request.),但同時還有其他人在操作組成員,如添加或刪除。

我們需要在代碼中處理這個異常。例如,我們可以通知用戶和信息用戶在我們得到此異常後重試以獲取成員。

+0

在這個問題上的任何更新?我們剛剛開始體驗這個問題。 –

相關問題