如何通过Graph API拉取指定会议室的所有Exchange事件?
Absolutely—this is totally feasible, especially with a high-permission application that has full calendar access. Here's how to go about it:
Key Context: Meeting Rooms as Resource Mailboxes
Meeting rooms in Exchange are treated as resource mailboxes, which means their calendars are accessible just like a regular user's calendar—you just need to target their email address instead of a user's.
Required Permissions
Since you're using a high-permission app, you'll want to use Application permissions (not delegated ones) for this operation. The relevant permissions are:
Calendars.Read: To read events from the meeting room's calendarCalendars.ReadWrite: If you also need to modify events (optional, based on your use case)
Make sure your app is granted these permissions via Azure AD admin consent—this is critical for accessing resource mailboxes without a user context.
API Endpoint & Example
The core endpoint to list events for a meeting room is:
GET /users/{meetingRoomEmail}/calendar/events
Replace {meetingRoomEmail} with the actual email address of your meeting room (e.g., conf-room-01@yourcompany.com).
Example Request (curl)
curl --request GET \ --url 'https://graph.microsoft.com/v1.0/users/conf-room-01@yourcompany.com/calendar/events' \ --header 'Authorization: Bearer {accessToken}' \ --header 'Content-Type: application/json'
Optional Query Parameters
You can refine the results with query parameters to get exactly what you need:
$select: Specify which fields to return (e.g.,$select=subject,start,end,location)$filter: Filter events by date range (e.g.,$filter=start/dateTime ge '2024-01-01T00:00:00Z' and end/dateTime le '2024-12-31T23:59:59Z')$expand: Include related resources like attendees (e.g.,$expand=attendees)
Important Notes
- Pagination: If the meeting room has a lot of events, Graph API will paginate results. Check the
@odata.nextLinkin the response to fetch subsequent pages. - Time Zones: By default, event times are returned in UTC. Use the
Prefer: outlook.timezoneheader to get times in your desired time zone (e.g.,Prefer: outlook.timezone="Pacific Standard Time"). - Access Validation: Ensure your app's service principal has been granted the necessary permissions and that the meeting room mailbox isn't restricted from external app access.
内容的提问来源于stack exchange,提问作者Hell.Bent

