2016-08-11 158 views
0

我正在嘗試獲取用戶的所有日曆的列表。此用戶具有委派權限查看所有會議室(資源)的日曆。如果我登錄到用戶的帳戶,並且能夠在「其他日曆」部分查看會議室日曆。我還在「其他日曆」部分創建了自己的日曆,名爲「測試」。缺少會議室日曆 - Office 365 API

當我先獲取所有日曆組,然後遍歷日曆組列表並獲取日曆時,「其他日曆」列表中只有「測試」日曆。

不知道爲什麼會出現這種情況。用戶也是全局管理員。

def get_access_info_from_authcode(auth_code, redirect_uri): 

    post_data = { 'grant_type': 'authorization_code', 
      'code': auth_code, 
      'redirect_uri': redirect_uri, 
      'scope': ' '.join(str(i) for i in scopes), 
      'client_id': client_registration.client_id(), 
      'client_secret': client_registration.client_secret() 
      } 

    r = requests.post(access_token_url, data = post_data, verify = verifySSL) 

    try: 
     return r.json() 
    except: 
     return 'Error retrieving token: {0} - {1}'.format(r.status_code, r.text) 

def get_access_token_from_refresh_token(refresh_token, resource_id): 
    post_data = { 'grant_type' : 'refresh_token', 
        'client_id' : client_registration.client_id(), 
        'client_secret' : client_registration.client_secret(), 
        'refresh_token' : refresh_token, 
        'resource' : resource_id } 

    r = requests.post(access_token_url, data = post_data, verify = verifySSL) 

    # Return the token as a JSON object 
    return r.json() 
def get_calendars_from_calendar_groups(calendar_endpoint, token, calendar_groups): 
    results = [] 
    for group_id in calendar_groups: 
     get_calendars = '{0}/me/calendargroups/{1}/calendars'.format(calendar_endpoint, group_id) 
     r = make_api_call('GET', get_calendars, token) 

     if (r.status_code == requests.codes.unauthorized): 
      logger.debug('Response Headers: {0}'.format(r.headers)) 
      logger.debug('Response: {0}'.format(r.json())) 
      results.append(None) 
     results.append(r.json()) 
    return results 
def get_calendars(calendar_endpoint, token, parameters=None): 
    if (not parameters is None): 
     logger.debug(' parameters: {0}'.format(parameters)) 

    get_calendars = '{0}/me/calendars'.format(calendar_endpoint)  
    if (not parameters is None): 
     get_calendars = '{0}{1}'.format(get_calendars, parameters) 
    r = make_api_call('GET', get_calendars, token) 
    if(r.status_code == requests.codes.unauthorized): 
     logger.debug('Unauthorized request. Leaving get_calendars.') 
     return None 
    return r.json() 

邏輯+代碼: 步驟1)獲得的授權URL:

authority = "https://login.microsoftonline.com/common" 
authorize_url = '{0}{1}'.format(authority, '/oauth2/authorize?client_id={0}&redirect_uri={1}&response_type=code&state={2}&prompt=consent') 

步驟2)打開URL帶我們到https://login.microsoftonline.com/common其中I登錄作爲用戶: enter image description here

步驟3)這將重定向回我的本地主機然後如下:

discovery_result = exchoauth.get_access_info_from_authcode(auth_code, Office365.redirect_uri) 

refresh_token = discovery_result['refresh_token'] 

client_id = client_registration.client_id() 
client_secret = client_registration.client_secret() 

access_token_json = exchoauth.get_access_token_from_refresh_token(refresh_token, Office365.resource_id) 

access_token = access_token_json['access_token'] 


calendar_groups_json = exchoauth.get_calendar_groups(Office365.api_endpoint, access_token) 
      cal_groups = {} 

if calendar_groups_json is not None: 
    for entry in calendar_groups_json['value']: 
     cal_group_id = entry['Id'] 
     cal_group_name = entry['Name'] 
     cal_groups[cal_group_id] = cal_group_name 

    calendars_json_list = exchoauth.get_calendars_from_calendar_groups(Office365.api_endpoint, 
        access_token, cal_groups) 

    for calendars_json in calendars_json_list: 
     if calendars_json is not None: 
      for ent in calendars_json['value']: 
       cal_id = ent['Id'] 
       cal_name = ent['Name'] 
       calendar_ids[cal_id] = cal_name 

讓我知道如果你需要任何其他信息

回答

0

委託令牌其與驗證碼撥款請求流只能得到登錄用戶的日曆。

如果要從特定房間獲取事件,可以使用客戶端憑據流的應用程序令牌請求。

Here是一個有用的鏈接供您參考。

+0

我還沒有試圖獲得特定房間的活動。我只是想列出當我調用API(/ me/calendargroups/{id} /日曆)時會返回的所有會議室日曆(用戶可以在其日曆列表中看到的)。 http://picresize.com/images/rsz_screenshot_from_2016-08-12_06-31-05.png 在此屏幕截圖中,您將看到4個日曆,Strongbad + Furnace是會議室日曆,該用戶具有委派權限。當我進行API調用時,它只返回日曆,測試結果。 – jayboss

+0

目前,Office 365 REST無法列出用戶委派的日曆。如果您希望Office 365 REST支持此功能,則可以從[here](https://officespdev.uservoice.com/)提交反饋。 –