You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Microsoft Graph API Python SDK中筛选会议室及日历事件?

使用新版Microsoft Graph API Python SDK筛选会议室及日历事件的问题

我正在使用新版Microsoft Graph API Python SDK,需获取会议室列表及相关日历事件。目前已实现基础获取功能,但需添加以下筛选条件:

  • 筛选特定楼层的会议室
  • 筛选支持轮椅通行的无障碍会议室
  • 筛选名称包含特定关键词的会议室
  • 获取指定时间段内这些会议室的所有已预订事件

我当前使用graph_client.places.graph_room.get()获取会议室及关联邮箱,使用graph_client.users.by_user_id(room_mail).calendar.events.get()获取日历事件,但不清楚如何添加筛选条件,且相关Python SDK文档较为匮乏。现有代码如下:

#!/usr/bin/env python3

import asyncio
from msgraph.generated.models.room import Room
from msgraph.generated.users.item.calendar.get_schedule.get_schedule_request_builder import GetScheduleRequestBuilder
from msgraph.generated.users.item.calendar.get_schedule.get_schedule_post_request_body import GetSchedulePostRequestBody
from msgraph import GraphServiceClient

from azure.identity import DeviceCodeCredential, CertificateCredential, AuthorizationCodeCredential

config = {
  'client_id': '<something>',
  'tenant_id': '<something>',
  'client_secret': '<something>',
  'authority': 'https://login.microsoftonline.com/<something>',
  'scope': ['https://graph.microsoft.com/.default'],
  'certificate_path': 'msal_crt_n_key.pem',
}
async def get_schedule_for_room(graph_client, mail):
    result = await graph_client.users.by_user_id(mail).calendar.events.get()
    return result

async def get_rooms(graph_client):
    return await graph_client.places.graph_room.get()

async def main():
    # azure.identity.aio
    print("Login using certificate")
    credential = CertificateCredential(
        tenant_id=config['tenant_id'],
        client_id=config['client_id'],
        certificate_path=config['certificate_path'])

    graph_client = GraphServiceClient(credential, config['scope']) # type: ignore
    print("Get list of rooms")
    rooms = await get_rooms(graph_client)
    print(f"Rooms: {rooms}")

    room_emails = [r.email_address for r in rooms.value]
    print(f"Rooms emails: {room_emails}")

    for mail in room_emails:
        calendar = await get_schedule_for_room(graph_client, mail)
        print(calendar)
        print(type(calendar))

asyncio.run(main())

内容的提问来源于stack exchange,提问作者Kodsama

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 10:06:09