Tag: microsoft graph

从所有Outlook联系人文件夹Microsoft Graph获取联系人

我使用Microsoft Graph使用以下代码检索联系人文件夹: GraphServiceClient client = new GraphServiceClient(new DelegateAuthenticationProvider( (requestMessage) => { requestMessage.Headers.Authorization = new AuthenticationHeaderValue(“Bearer”, accessToken); return Task.FromResult(0); })); var contactsData = await client .Me .Contacts .Request() .Top(1000) .GetAsync(); 上面的代码返回联系人,但只返回默认文件夹中的联系人。 我想从所有用户的文件夹中检索联系人。 我尝试先获取文件夹,然后尝试获取联系人,但是当联系人为null ,它会返回Null Reference Exception 。 var Folders = client .Me .ContactFolders .Request() .Top(1000) .GetAsync(); Folders.Wait(); var contacts = Folders.Result.SelectMany(a => a.Contacts).ToList();

通过MVC Web App中的ViewModel调用Graph API

我正在尝试使用Graph API来创建我自己的Web应用程序导航栏的“用户配置文件”部分。 为此,我对我的UserProfile控制器的GetUser操作进行了AJAX调用: $.ajax({ type: “GET”, url: “@Url.Action(“GetUser”, “UserProfile”, null)”, dataType: “json”, success: function (data, status, xhr) { console.log(“in AJAX”); $(“.img-circle, .user-image”).attr(“src”, data.Picture); $(“#user-menu-expanded”).text(data.User.DisplayName + ” – ” + data.User.JobTitle); $(“#user-menu-spinner”).remove(); console.log(data); }, error: function (ex) { console.log(ex); } }); 控制器将我的UserProfileViewModel作为Json返回,我用它来替换上面的元素,如我的AJAX成功函数所示。 UserProfile控制器: public JsonResult GetUser() { var model = new UserProfileViewModel(); return Json(model, JsonRequestBehavior.AllowGet); } […]

C#MVC和MS Graph问题

这里陷入了两难境地。 我有一个C#MVC应用程序(连接到sharepoint),我需要找到一种从Azure Active Directory检索用户的方法(Sharepoint不为这种类型的插件提供人员选择器)。 我想要实现的目标 – >一个搜索框,在按钮上单击它会在AD中搜索用户电子邮件或名称(可能是电子邮件),然后它应该返回一个包含Azure AD用户ID和显示名称的json。 我想过使用MS Graph来做到这一点,但我没有找到一个很好的教程来实现对MVC的Graph调用。 加! id就像一种不要求用户做任何事情的方式,只需单击搜索按钮(因此最好没有用户的身份validation令牌,没有图形应用登录或此类事情)。 这可能吗 ? 我甚至会在JS中这样做,因为它将是一个相当“封闭”的应用程序,但我记录图形实现的方式让我哭…(所以……是的……请不要指向MS图形实现文档,它的awfull)。 任何帮助将不胜感激,谢谢。

如何使用Microsoft.Graph将文件附加到Sharepoint中的项目

Microsoft.Graph Sharepoint api允许使用PATCH请求更新列表项https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/listitem_update 。 但是如何生成正确的请求? using (HttpClient pacthClient = new HttpClient()) { var mediaType = new MediaTypeWithQualityHeaderValue(“application/json”); pacthClient.DefaultRequestHeaders.Accept.Add(mediaType); pacthClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(“Bearer”, userToken); using (HttpRequestMessage requestMessage = new HttpRequestMessage(new HttpMethod(“PATCH”), $”{uri}/{id}”)) { requestMessage.Content = byteArrayContent ??? using (HttpResponseMessage responseMessage = await pacthClient.SendAsync(requestMessage)) { } } }

带有Service / Daemon应用程序的Microsoft Graph CSharp SDK和OneDrive for Business – Quota facet返回null

我正在编写针对OneDrive for Business Microsoft Graph CSharp SDK编码,我正在尝试撤回特定User数据并请求返回Quota信息。 我的请求: var user = await graphServiceClient.Users[“test@test.onmicrosoft.com”].Request().GetAsync(); var drive = await graphServiceClient.Drives[“test@test.onmicrosoft.com”].Request().GetAsync(); var quotaTotal = drive.Quota.Used; var displayName = user.DisplayName; var driveType = drive.DriveType; var driveId = drive.Id; 问题 – 返回的数据全为null 。 Microsoft Graph SDK是否支持撤回OneDrive for Bussiness帐户的Quota方面? 更新 我还提供了client_id , client_secret和tenant_name来对应用程序级权限进行身份validation。 更新 添加了drive的屏幕截图,因为它返回所有null。

Microsoft.Graph发送带附件的邮件

using Microsoft.Graph IMessageAttachmentsCollectionPage Message.Attachments 我似乎无法使用FileAttachment.ContentBytes中的任何“ContentBytes”。 我的示例来自Microsoft https://github.com/microsoftgraph/aspnet-snippets-sample 。 // Create the message. Message email = new Message { Body = new ItemBody { Content = Resource.Prop_Body + guid, ContentType = BodyType.Text, }, Subject = Resource.Prop_Subject + guid.Substring(0, 8), ToRecipients = recipients, HasAttachments = true, Attachments = new[] { new FileAttachment { ODataType = “#microsoft.graph.fileAttachment”, ContentBytes […]

使用Microsoft Graph更改Azure AD的密码

我计划使用Azure AD Graph API,但随后在Microsoft文档中注意到有关使用Microsoft Graph API的建议。 是否提供了更改用户密码的文档? string result = Task.Run(async() => { return await GetAccessToken(); }).GetAwaiter().GetResult(); var graphserviceClient = new GraphServiceClient( new DelegateAuthenticationProvider( (requestMessage) => { requestMessage.Headers.Authorization = new AuthenticationHeaderValue(“bearer”, result); return Task.FromResult(0); })); var changePasswordRequest = graphserviceClient.Me.ChangePassword(“oldpassword”, “newpassword”); 但是我认为这还不够。 有可用的文件吗?

Microsoft Graph SDK – 登录

是否可以仅使用MS Graph登录一次? 目前,每当我调用graphServiceClient时,它都会要求我登录或选择已登录的用户。 有没有办法可以避免选择登录用户的过程? 提前致谢。 目前这是我初始化graphService的方式。 public static GraphServiceClient GetAuthenticatedClient() { GraphServiceClient graphClient = new GraphServiceClient( new DelegateAuthenticationProvider( async (requestMessage) => { string appID = ConfigurationManager.AppSettings[“ida:AppId”]; PublicClientApplication PublicClientApp = new PublicClientApplication(appID); string[] _scopes = new string[] { “Calendars.read”, “Calendars.readwrite” }; AuthenticationResult authResult = null; authResult = await PublicClientApp.AcquireTokenAsync(_scopes); //Opens Microsoft Login Screen // Append the […]