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

PHP集成Zoom OAuth创建会议遇Invalid access token错误的解决咨询

问题

我正在尝试通过OAuth用PHP集成Zoom以创建会议,获取token的方法如下:

private function auth_token()
{
    $client = new Client();

    //====== get Auth token =======
    $response = $client->post('https://zoom.us/oauth/token', [
        'form_params' => [
            'grant_type' => 'client_credentials',
            'client_id' => $this->apiKey,
            'client_secret' => $this->apiSecret,
        ],
    ]);
    $accessToken = json_decode($response->getBody())?->access_token ;

    return $accessToken;
}

确认token已成功获取,但调用创建会议的方法时:

public function create_meeting()
{
    try {
        $accessToken = $this->auth_token();

        $client = new Client();

        $response = $client->post('https://api.zoom.us/v2/users/me/meetings', [
            'form_params' => [
                'topic' => 'Your Meeting Topic',
                'type' => 2, // Scheduled Meeting
            ],
            'headers' => [
                'Authorization' => "Bearer $accessToken",
            ],
        ]);

        $responseData = json_decode($response->getBody(), true);

        echo 'Meeting created: ' . print_r($responseData, true) . PHP_EOL;
    } catch (Exception $e) {
        echo 'Error creating meeting: ' . $e->getMessage() . PHP_EOL;
    }
}

返回错误:

{
  "code": 124,
  "message": "Invalid access token."
}
解决方案
  • 授权模式不匹配接口要求
    你使用的client_credentials授权模式获取的token仅适用于服务器到服务器的无用户上下文接口,无法解析/users/me/meetings中的me(该模式没有关联具体用户)。解决方式二选一:

    1. 改用Authorization Code Grant模式,获取绑定用户上下文的access token,此时可以继续使用/users/me/meetings接口;
    2. 保留client_credentials模式,但调用接口时替换me为具体的用户ID或邮箱,同时确保你的Zoom应用拥有该用户的会议管理权限。
  • 请求体格式错误
    Zoom创建会议的接口要求请求体为JSON格式,但你当前用form_params发送的是application/x-www-form-urlencoded数据,导致API无法正确解析请求,进而触发token验证失败的错误。修改请求代码如下:

    // 替换{USER_ID_OR_EMAIL}为实际用户ID/邮箱(client_credentials模式必须指定)
    $response = $client->post('https://api.zoom.us/v2/users/{USER_ID_OR_EMAIL}/meetings', [
        'json' => [
            'topic' => 'Your Meeting Topic',
            'type' => 2, // Scheduled Meeting
        ],
        'headers' => [
            'Authorization' => "Bearer $accessToken",
            'Content-Type' => 'application/json',
        ],
    ]);
    
  • 检查权限范围与有效性

    1. 在Zoom开发者平台的应用设置中,确认已添加meeting:write或meeting:write:admin权限范围;
    2. 若使用Authorization Code模式,需确保用户已完成权限授权;
    3. 可通过解析token的payload(用JWT工具)验证exp(过期时间)、scope(权限范围)等字段是否正确。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 11:01:32