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(该模式没有关联具体用户)。解决方式二选一:- 改用Authorization Code Grant模式,获取绑定用户上下文的access token,此时可以继续使用
/users/me/meetings接口; - 保留
client_credentials模式,但调用接口时替换me为具体的用户ID或邮箱,同时确保你的Zoom应用拥有该用户的会议管理权限。
- 改用Authorization Code Grant模式,获取绑定用户上下文的access token,此时可以继续使用
请求体格式错误
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', ], ]);检查权限范围与有效性
- 在Zoom开发者平台的应用设置中,确认已添加
meeting:write或meeting:write:admin权限范围; - 若使用Authorization Code模式,需确保用户已完成权限授权;
- 可通过解析token的payload(用JWT工具)验证
exp(过期时间)、scope(权限范围)等字段是否正确。
- 在Zoom开发者平台的应用设置中,确认已添加
内容的提问来源于stack exchange,提问作者Mohamed Zayed
相关产品推荐
相关产品推荐

