简体   繁体   English

会议室日历丢失-Office 365 API

[英]Meeting room calendars missing - Office 365 API

I am trying to get the list of all calendars for a user. 我正在尝试获取用户的所有日历的列表。 This user has delegate permissions to view the calendar of all the meeting rooms (resources). 该用户具有查看所有会议室(资源)的日历的委托权限。 If I log into the user's account and I am able to see the meeting room calendars in the "Other Calendars" section. 如果我登录到该用户的帐户,并且能够在“其他日历”部分中看到会议室日历。 I also created my own calendar called "Test" in the "Other Calendars" section. 我还在“其他日历”部分中创建了自己的日历,称为“测试”。

When I get all the calendar groups first and then iterate through the calendar group list and get the calendars, the list for "Other Calendars" only has "Test" calendar. 当我首先获取所有日历组,然后遍历日历组列表并获取日历时,“其他日历”列表仅具有“测试”日历。

Not sure why this is the case. 不知道为什么会这样。 The user is a global administrator as well. 该用户也是全局管理员。

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()

Logic + Code: Step 1) Get the authorization URL: 逻辑+代码:步骤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')

Step 2) Opening the URL takes us to https://login.microsoftonline.com/common where I login as the user: 步骤2)打开URL,我们进入https://login.microsoftonline.com/common ,我以用户身份登录: 在此处输入图片说明

Step 3) This redirects back to my localhost then the following: 步骤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

Let me know if you need any other information 让我知道您是否需要其他信息

The delegate-token which request with the Auth code grant flow only able to get the calendars of sign-in user. 带有Auth代码授予流的请求的委托令牌只能获取登录用户的日历。

If you want to the get the events from the specific room, you can use the app-only token request with client credential flow . 如果要从特定房间获取事件,可以将仅应用程序令牌请求与客户端凭据流一起使用

Here is an helpful link for your reference. 是一个有用的链接,供您参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM