Я использую следующий код: -
using Microsoft.Graph;
using Microsoft.Identity.Client;
using System;
using System.Collections;
using System.Text.RegularExpressions;
namespace MSGraphAPI
{
class Program
{
private static string clientId = "XXXX";
private static string tenantID = "XXXXX";
private static string objectId = "XXXXXXXX";
private static string clientSecret = "XXXXX";
static async System.Threading.Tasks.Task Main(string[] args)
{
Console.WriteLine(Regex.IsMatch(strToCheck, pattern, RegexOptions.IgnoreCase));
int Flag = 0;
var tenantId = "XXXX.onmicrosoft.com";
var clientId = "XXXXX";
var scopes = new string[] { "https://graph.microsoft.com/.default" };
var confidentialClient = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithAuthority($"https://login.microsoftonline.com/XXXX.onmicrosoft.com/v2.0")
.WithClientSecret(clientSecret)
.Build();
GraphServiceClient graphServiceClient =
new GraphServiceClient(new DelegateAuthenticationProvider(async (requestMessage) => {
// Retrieve an access token for Microsoft Graph (gets a fresh token if needed).
var authResult = await confidentialClient
.AcquireTokenForClient(scopes)
.ExecuteAsync();
// Add the access token in the Authorization header of the API request.
requestMessage.Headers.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", authResult.AccessToken);
})
);
// Make a Microsoft Graph API query
var users = await graphServiceClient.Users.Request().GetAsync();
do
{
foreach (User user in users)
{
Console.WriteLine(user.DepartmentName);
Console.WriteLine(user.DisplayName);
var Peoples = await graphServiceClient.Users[user.Id].People.Request().GetAsync();
foreach(IUserPeopleCollectionPage People in Peoples)
{
Console.WriteLine(People.CurrentPage.ToString());
}
}
while (users.NextPageRequest != null && (users = await users.NextPageRequest.GetAsync()).Count > 0);
Console.WriteLine("------");
Console.WriteLine(Flag);
}
}
}
Я не могу получить DepartmentName.
Я могу печатать другие значения в Peoples, которые представляют собой данные типа IUserPeopleCollectionPage, которые содержат несколько значений, таких как DisplayName, Department, CurrentPage (содержит 10 данных) В основном я пытаюсь l oop над данными, используя foreach, но не могу получить результат.
Пожалуйста, помогите.