使用Microsoft Graph的O365组udpate [英] O365 group udpate using Microsoft Graph

查看:96
本文介绍了使用Microsoft Graph的O365组udpate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码是

List<KeyValuePair<string, string>> vals = new List<KeyValuePair<string, string>>();

                string authString = "https://login.microsoftonline.com/" + tenantName;
                string resource = "https://graph.microsoft.com";

                AuthenticationContext authenticationContext = new AuthenticationContext(authString, false);

                vals.Add(new KeyValuePair<string, string>("client_id", clientId));
                vals.Add(new KeyValuePair<string, string>("resource", resource));
                vals.Add(new KeyValuePair<string, string>("username", userName));
                vals.Add(new KeyValuePair<string, string>("password", password));
                vals.Add(new KeyValuePair<string, string>("grant_type", "client_credentials"));
                vals.Add(new KeyValuePair<string, string>("client_secret", key));

                string url = string.Format("https://login.windows.net/{0}/oauth2/token", tenantName);

                using (HttpClient httpClient = new HttpClient())
                {
                    httpClient.DefaultRequestHeaders.Add("Cache-Control", "no-cache");

                    HttpContent content = new FormUrlEncodedContent(vals);
                    HttpResponseMessage hrm = httpClient.PostAsync(url, content).Result;

                    AuthenticationResponse authenticationResponse = null;
                    if (hrm.IsSuccessStatusCode)
                    {
                        Stream data = await hrm.Content.ReadAsStreamAsync();
                        DataContractJsonSerializer serializer = new
                        DataContractJsonSerializer(typeof(AuthenticationResponse));
                        authenticationResponse = (AuthenticationResponse)serializer.ReadObject(data);

                        var accessToken = authenticationResponse.access_token;

                        var a = UnifiedGroupsUtility.GetUnifiedGroup(groupID, accessToken);
                        // Update description and group logo programatically
                        
                        Stream groupLogoStream1 = new FileStream(@"D:\\sandviklogo.png",
                                    FileMode.Open, FileAccess.Read);

                        UnifiedGroupsUtility.UpdateUnifiedGroup(groupID, accessToken, isPrivate: true,
        owners: ownersList, members: ownersList);

                        UnifiedGroupsUtility.UpdateUnifiedGroup(groupID, accessToken, isPrivate: true, description: "Dddd",
        groupLogo: groupLogoStream1);

                        groupLogoStream1.Close();

                        // Delete group programatically
                        //UnifiedGroupsUtility.DeleteUnifiedGroup(groupId, accessToken);

                    }
                }


推荐答案

此代码一直工作到昨天晚上,但今天早上组徽标更新代码失败.

This code was working till yesterday evening but today morning the group logo update code fails.

UnifiedGroupsUtility.UpdateUnifiedGroup(groupID,accessToken,isPrivate:true,描述:"Dddd",groupLogo:groupLogoStream1)失败.

Fails on UnifiedGroupsUtility.UpdateUnifiedGroup(groupID, accessToken, isPrivate: true, description: "Dddd", groupLogo: groupLogoStream1); 

错误详细信息

Code: ErrorAccessDenied
Message: Access is denied. Check credentials and try again.

Inner error



这篇关于使用Microsoft Graph的O365组udpate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆