簡體   English   中英

會議室日歷丟失-Office 365 API

[英]Meeting room calendars missing - 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 ,我以用戶身份登錄: 在此處輸入圖片說明

步驟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

讓我知道您是否需要其他信息

帶有Auth代碼授予流的請求的委托令牌只能獲取登錄用戶的日歷。

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM