![](/img/trans.png)
[英]Azure & Microsoft Graph: Access denied accessing inbox, using Client Secret
[英]Making Microsoft Azure Graph Client for .net emit $expand
我正在嘗試檢索目錄中所有用戶的(分頁)列表,並擴展了manager屬性。 當我運行以下HTTP查詢時,它按我的意願工作:
https://graph.windows.net/DOMAIN/users/?$expand=manager&api-version=2013-11-08
但是,我似乎沒有掌握如何使用Azure AD Graph客戶端進行相同的查詢。 這就是我正在嘗試的:
var userResult = _activeDirectoryClient.Users.Expand(x => x.Manager).ExecuteAsync().Result;
我在https://github.com/AzureADSamples/ConsoleApp-GraphAPI-DotNet/blob/master/GraphConsoleAppV3/Program.cs上的示例中修改了以下內容,請試一試:
List<IUser> usersList = null; IPagedCollection<IUser> searchResults = null; try { IUserCollection userCollection = activeDirectoryClient.Users; userResult = userCollection.ExecuteAsync().Result; usersList = searchResults.CurrentPage.ToList(); } catch (Exception e) { Console.WriteLine("\\nError getting User {0} {1}", e.Message, e.InnerException != null ? e.InnerException.Message : ""); } if (usersList != null && usersList.Count > 0) { do { usersList = searchResults.CurrentPage.ToList(); foreach (IUser user in usersList) { Console.WriteLine("User DisplayName: {0} UPN: {1} Manager: {2}", user.DisplayName, user.UserPrincipalName, user.Manager); } searchResults = searchResults.GetNextPageAsync().Result; } while (searchResults != null); } else { Console.WriteLine("No users found"); }
GraphClient尚未實現Graph API中的所有功能。
隨着時間的推移,新功能將被添加到GraphClient中,並將在AAD團隊博客上公布:
http://blogs.msdn.com/b/aadgraphteam/
並且將在nuget包(Microsoft Azure Active Directory圖形客戶端庫)中提供更新。
您可以通過對問題中的url進行Http調用來獲得所需內容,並像Json一樣得到響應:
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://graph.windows.net/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("DOMAIN/users/?$expand=manager&api-version=2013-11-08");
if (response.IsSuccessStatusCode)
{
// TODO: Deserialize the response here...
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.