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

如何通过Graph API以应用身份创建可共享链接的即席在线会议?

解决Graph API创建即席在线会议的问题

核心问题分析

你采用的是**客户端凭证(client_credentials)**授权模式,这种模式没有当前用户上下文,所以/me端点无法生效,必须指定具体用户ID(/users/{user_id})来创建会议——因为Teams会议必须关联一个租户内的微软365用户账号。

修正步骤与代码调整

  1. 替换API端点:将/me/onlineMeetings改为/users/{user_id}/onlineMeetings,其中{user_id}可以是目标用户的邮箱或Azure AD对象ID。
  2. 移除冗余参数:请求体里的Authorisation参数完全多余,Graph API仅识别请求头中的Bearer Token。
  3. 确认权限配置:在Azure AD应用中,必须添加OnlineMeetings.ReadWrite.All应用权限(客户端凭证模式不支持委派权限),且已完成管理员同意。

修正后的完整代码

$client = new GuzzleHttp\Client();

// 获取访问令牌
$req_url = "https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token";
$request = $client->post($req_url, [
    "headers" => [
        "Content-Type" => "application/x-www-form-urlencoded"
    ],
    "body" => http_build_query([
        "client_id" => get_option("azure_clientID"),
        "client_secret" => get_option("azure_clientSecret"),
        "grant_type" => "client_credentials",
        "scope" => "https://graph.microsoft.com/.default"
    ])
]);

$access_token = json_decode((string)$request->getBody())->access_token;

// 创建在线会议
$target_user_id = "user@yourdomain.com"; // 替换为租户内有权创建会议的用户邮箱/对象ID
$meeting = $client->post("https://graph.microsoft.com/v1.0/users/{$target_user_id}/onlineMeetings", [
    "headers" => [
        "Content-Type" => "application/json",
        "Authorization" => "Bearer {$access_token}"
    ],
    "body" => json_encode([
        "startDateTime" => "2024-05-20T14:30:00.0000000-07:00", // 必须使用未来的ISO 8601格式时间
        "endDateTime" => "2024-05-20T15:00:00.0000000-07:00",
        "subject" => "即席在线会议",
        "participants" => [
            "attendees" => [
                [
                    "identity" => [
                        "user" => [
                            "id" => $target_user_id
                        ]
                    ],
                    "role" => "presenter"
                ]
            ]
        ]
    ])
]);

// 提取会议加入链接
$meeting_response = json_decode((string)$meeting->getBody());
$join_link = $meeting_response->joinWebUrl;

关键注意事项

  • 用户ID获取:可通过Graph API的/users端点查询租户内用户列表,获取对应ID或邮箱。
  • 时间有效性:startDateTime必须设置为未来时间,否则会返回参数错误。
  • 权限验证:如果遇到403错误,检查Azure AD应用是否已完成OnlineMeetings.ReadWrite.All权限的管理员同意。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 22:24:53