Hi @APIPointNewbie , this is my code and my test result. Pls note that you need to give the api permission in azure portal before, here I used client credential flow, so I set application permission but not delegate permission.
using Azure.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Graph;
using System.Linq;
using System.Threading.Tasks;
namespace WebApplication3.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
public async Task<string> testAsync() {
var def = new[] { "https://graph.microsoft.com/.default" };
var tenantId = "tenant_name.onmicrosoft.com";
var clientId = "azure_ad_app_id_here";
var clientSecret = "client_secret_here";
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, def);
DriveItemSearchCollectionPage a = (DriveItemSearchCollectionPage)await graphClient.Users["my_user_id"].Drive.Root.Search("win-arm").Request().GetAsync();
return a.FirstOrDefault<DriveItem>().Name;
}
}
}
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards,
TinyWang