2016-05-11 172 views
0

是否可以使用Microsoft.Azure.ActiveDirectory.GraphClient創建組時指定組的類型?創建天藍色廣告組

例如與代碼:

Group groupToBeAdded = new Group 
{ 
    DisplayName = "group name", 
    Description = string.Empty, 
    MailNickname = member.Name, 
    MailEnabled = true, 
    SecurityEnabled = true, // Set to true for security-enabled groups. Set to false if creating an Office 365 group 
    Mail = AppConstants.EmailProperty 
}; 

但我不能指定組類型(「統一」,「DynamicMembership」,「」)

+0

我搜索這個職位:http://stackoverflow.com/questions/37065503/how-can-i-create-group-mail-alias-using-office-365-api-in-c-sharp 。我發現這篇文章。我會嘗試 – user3668585

回答

0

我創建了這個組!

AuthenticationContext authenticationContext = new AuthenticationContext("https://login.windows.net/" + Constants.TenantName, false); 
      var clientCredential = new ClientCredential(Constants.ClientId, Constants.ClientSecret); 
      AuthenticationResult authenticationResult = authenticationContext.AcquireToken("https://graph.microsoft.com/", clientCredential); 
      string token = authenticationResult.AccessToken; 
      string content = @"{ 
       ""displayName"": ""mailgrouptest"",  
       ""groupTypes"": [""Unified""], 
       ""mailEnabled"": true, 
       ""mailNickname"": ""mailalias"", 
       ""securityEnabled"": false 
      }"; 
      using (var client = new HttpClient()) 
      { 
       string uri = "https://graph.microsoft.com/v1.0/groups" 
       using (var request = new HttpRequestMessage(HttpMethod.Post, uri)) 
       { 
        request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); 
        request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); 
        string json = content; 
        request.Content = new StringContent(json, Encoding.UTF8, "application/json"); 
        using (HttpResponseMessage response = client.SendAsync(request).Result) 
        { 
         //response.IsSuccessStatusCode 
        } 
       } 
      } 
相關問題