Google Smart Home Action对接Express API:令牌请求无参数问题求助
解决Google Smart Home令牌请求无参数的问题
- Google的令牌交换请求是POST方式,而非GET,所以不能通过
res.query获取参数,需从请求体中读取。 - 检查Express中间件配置:必须添加解析请求体的中间件,否则无法读取参数:
- 针对Google默认使用的
x-www-form-urlencoded格式,添加:app.use(express.urlencoded({ extended: true })); - 若为JSON格式,添加:
app.use(express.json());
- 针对Google默认使用的
- 正确获取参数:在令牌交换端点中使用
req.body提取所需字段,示例代码:app.post('/oauth/token', (req, res) => { const { client_id, client_secret, grant_type, code, redirect_uri } = req.body; // 执行令牌交换逻辑 res.json({ access_token: 'your_generated_token', token_type: 'Bearer', expires_in: 3600 }); }); - 验证端点配置:确认Google Action控制台中令牌交换端点的请求方法为POST,且URL与Express路由完全一致,无拼写错误。
内容的提问来源于stack exchange,提问作者Kyaw Walar Htwe
相关产品推荐
相关产品推荐

