我正在尝试通过Oauth从Zoom api接收访问令牌。无论我尝试以什么形式发送正文,'Content-Type':'application/json‘或Content-Type:application/x-www-form-urlencoded,,它总是错误到{ reason:'Missing grant type',error:'invalid_request’}。
var options = {
method: "POST",
url: "https://zoom.us/oauth/token",
body: JSON.stringify({
grant_type: "authorization_code",
code: process.env.AUTH_CODE,
}),
redirect_uri: "https://zoom.us",
};
var header = {
headers: {
Authorization:
"Basic " +
Buffer.from(process.env.ID + ":" + process.env.SECRET).toString("base64"),
},
"Content-Type": "application/json",
};
var tokCall = () =>
axios
.post("https://zoom.us/oauth/token", options, header)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error.response);
});
tokCall();我相当确定答案在于Oauth接收数据的数据类型,或者Oauth是否接收正文。我们将非常感谢您提出的任何建议。
发布于 2021-08-02 13:36:00
之所以抛出这个错误,是因为您将数据作为post请求的主体发送,而Request Access Token Zoom API希望将它们作为查询参数来查找,您可能会将这些参数称为查询字符串。
参考
https://marketplace.zoom.us/docs/guides/auth/oauth#local-test
变化
var options = {
method: "POST",
url: "https://zoom.us/oauth/token",
body: JSON.stringify({
grant_type: "authorization_code",
code: process.env.AUTH_CODE,
}),
redirect_uri: "https://zoom.us",
};至
var options = {
method: "POST",
url: "https://zoom.us/oauth/token",
params: {
grant_type: "authorization_code",
code: process.env.AUTH_CODE,
redirect_uri: "<must match redirect uri used during the app setup on zoom>"
},
};Content-Type头应该设置为application/x-www-form-urlencoded,因为这是zoom API本身的要求。
顺便说一句,axios要求您将请求的主体字段/对象命名为数据,而且也不需要JSON.stringify()方法,因为axios会在幕后为您做这件事
https://stackoverflow.com/questions/66583114
复制相似问题