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

创建Zoom会议时提示无效访问令牌,密钥有效却报错求助

解决Zoom API "Invalid Access Token" 错误

核心问题

你当前代码直接将API Key和Secret作为HTTP基本认证参数传入,但Zoom API不支持这种认证方式。无论是JWT认证还是Server-to-Server OAuth,都需要生成对应令牌并放在Authorization请求头中,直接传密钥会被判定为无效令牌。

修正方案:使用JWT认证

如果你的Zoom应用是JWT类型,按以下步骤修改代码:

  1. 先安装JWT依赖库:
pip install python-jose[cryptography]
  1. 修改代码生成并使用JWT令牌:
import requests
import json
from jose import jwt
from datetime import datetime, timedelta

API_KEY = '你的API KEY'
API_SEC = '你的SECRET KEY'
zoom_api_url = 'https://api.zoom.us/v2/users/me/meetings'

# 生成JWT令牌
def generate_jwt_token(api_key, api_secret):
    payload = {
        # 签发者为API Key
        "iss": api_key,
        # 令牌有效期设为1小时,不超过Zoom限制
        "exp": datetime.utcnow() + timedelta(hours=1)
    }
    # 用HS256算法签名
    token = jwt.encode(payload, api_secret, algorithm='HS256')
    return token

meeting_details = {
    "topic": "测试Zoom会议",
    "type": 2,
    "start_time": "2024-02-27T10:00:00",
    "duration": 45,  # 此处应为整数,而非字符串
    "timezone": "Europe/Madrid",
    "agenda": "测试会议",
    "settings": {
        "host_video": True,  # 使用布尔值而非字符串
        "participant_video": True,
        "join_before_host": False,
        "mute_upon_entry": False,
        "watermark": True,
        "audio": "voip",
        "auto_recording": "cloud"
    }
}

headers = {
    'Content-Type': 'application/json',
    'Authorization': f'Bearer {generate_jwt_token(API_KEY, API_SEC)}'
}

response = requests.post(zoom_api_url, headers=headers, data=json.dumps(meeting_details))
print(response.json())

额外排查点

  • 确认Zoom应用类型:如果是Server-to-Server OAuth,需先通过https://zoom.us/oauth/token接口获取access_token,再用Bearer {access_token}作为认证头,而非直接生成JWT。
  • 检查API Key和Secret是否对应正确的应用,未混淆其他应用密钥。
  • 确保JWT的exp时间为UTC时间,且未过期(有效期建议不超过1小时)。
  • 会议参数中的布尔值需用Python原生True/False,避免字符串格式导致的参数错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 09:46:14