2017-06-07 155 views
1

因此,這是問題所在。我在MSDN和Stack上搜索了所有內容,但是如何在Office365中訪問共享日曆,卻沒有一個明確的答案(或者今天甚至可能)?從Office 365 API獲取共享日曆

我跟着this教程,這裏是得罪方法:

public async Task<ActionResult> Index() 
    { 
     List<MyCalendar> myCalendars = new List<MyCalendar>(); 

     var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value; 
     var userObjectId = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value; 

     AuthenticationContext authContext = new AuthenticationContext(SettingsHelper.Authority, new ADALTokenCache(signInUserId)); 

     try 
     { 
      DiscoveryClient discClient = new DiscoveryClient(SettingsHelper.DiscoveryServiceEndpointUri, 
       async() => 
       { 
        var authResult = await authContext.AcquireTokenSilentAsync(SettingsHelper.DiscoveryServiceResourceId, new ClientCredential(SettingsHelper.ClientId, SettingsHelper.AppKey), new UserIdentifier(userObjectId, UserIdentifierType.UniqueId)); 

        return authResult.AccessToken; 
       }); 

      var discoveryCapabilitiesResult = await discClient.DiscoverCapabilitiesAsync(); 

      var dcr = await discClient.DiscoverCapabilityAsync("Calendar"); 

      OutlookServicesClient exClient = new OutlookServicesClient(dcr.ServiceEndpointUri, 
       async() => 
       { 
        var authResult = await authContext.AcquireTokenSilentAsync(dcr.ServiceResourceId, new ClientCredential(SettingsHelper.ClientId, SettingsHelper.AppKey), new UserIdentifier(userObjectId, UserIdentifierType.UniqueId)); 

        return authResult.AccessToken; 
       }); 

      //var calendarsResult = await exClient.Me.Calendars.ExecuteAsync(); 

      var calendarsResult = await exClient.Me.Calendars.ExecuteAsync(); 


      do 
      { 
       var calendars = calendarsResult.CurrentPage; 
       foreach (var c in calendars) 
       { 
        myCalendars.Add(new MyCalendar { DisplayName = c.Name }); 
       } 

       calendarsResult = await calendarsResult.GetNextPageAsync(); 

      } while (calendarsResult != null); 
     } 
     catch (AdalException exception) 
     { 
      //handle token acquisition failure 
      if (exception.ErrorCode == AdalError.FailedToAcquireTokenSilently) 
      { 
       authContext.TokenCache.Clear(); 

       //handle token acquisition failure 
      } 
     } 

     return View(myCalendars); 
    } 

此功能將在「我的日曆」,而不是其他人只返回日曆(見圖片)

Multiple calendars

我只獲得第一個 - 這是我的日曆。 「我的日曆」下的第二個是與我共享的(我不是作者,其他人是,我有r/w),在「共享日曆」下的是公司範圍內的一個(我也有這個r/w權限)。

有沒有辦法讓所有這些?在portal.azure.com我的應用程序被添加和我設置了兩個煤礦的權限和共享日曆:

Permissions

我不知道該怎麼做。聯繫人正常工作,但我找不到任何共享日曆的方式。

回答

0

基於測試,Microsoft Graph可以獲取所有日曆。這裏是休息,供大家參考:

從chenchenLi共享日曆到南嶼: enter image description here

查詢了從南嶼日曆:enter image description here

更多關於微軟圖表REST詳細拿到日曆,可以請參考以下鏈接:

List calendars

+0

您好,我測試了這一點,但沒有運氣 - 我仍然只得到一個日曆,但沒有其他(共享)日曆(從我的第一篇文章)。 http://imgur.com/a/k7BuA – nighthawk

+0

你是如何分享日曆的?我使用[outlook portal](https://outlook.office365.com/)上的按鈕** share **共享日曆,並在用戶接受後,Microsoft Graph成功列出日曆。 –

+0

日曆由我們的Office365管理員在整個公司範圍內共享。每個員工都有權限,但我無法在Graph API上看到它。它是從全球地址簿添加的。你可以用別人共享的日曆進行測試,你不是作者嗎? – nighthawk