缺少会议室日历 - Office 365 API
问题描述:
我正在尝试获取用户的所有日历的列表。此用户具有委派权限查看所有会议室(资源)的日历。如果我登录到用户的帐户,并且能够在“其他日历”部分查看会议室日历。我还在“其他日历”部分创建了自己的日历,名为“测试”。缺少会议室日历 - 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登录作为用户:
步骤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
让我知道如果你需要任何其他信息
我还没有试图获得特定房间的活动。我只是想列出当我调用API(/ me/calendargroups/{id} /日历)时会返回的所有会议室日历(用户可以在其日历列表中看到的)。 http://picresize.com/images/rsz_screenshot_from_2016-08-12_06-31-05.png 在此屏幕截图中,您将看到4个日历,Strongbad + Furnace是会议室日历,该用户具有委派权限。当我进行API调用时,它只返回日历,测试结果。 – jayboss
目前,Office 365 REST无法列出用户委派的日历。如果您希望Office 365 REST支持此功能,则可以从[here](https://officespdev.uservoice.com/)提交反馈。 –