首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过Oauth请求访问Zoom API的令牌-错误‘缺少授权类型’

通过Oauth请求访问Zoom API的令牌-错误‘缺少授权类型’
EN

Stack Overflow用户
提问于 2021-03-11 21:02:38
回答 1查看 217关注 0票数 1

我正在尝试通过Oauth从Zoom api接收访问令牌。无论我尝试以什么形式发送正文,'Content-Type':'application/json‘或Content-Type:application/x-www-form-urlencoded,,它总是错误到{ reason:'Missing grant type',error:'invalid_request’}。

代码语言:javascript
复制
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是否接收正文。我们将非常感谢您提出的任何建议。

EN

回答 1

Stack Overflow用户

发布于 2021-08-02 13:36:00

之所以抛出这个错误,是因为您将数据作为post请求的主体发送,而Request Access Token Zoom API希望将它们作为查询参数来查找,您可能会将这些参数称为查询字符串。

参考

https://marketplace.zoom.us/docs/guides/auth/oauth#local-test

Image of page from link to highlight the use of query parameters and content-type requirement for API call

变化

代码语言:javascript
复制
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",
};

代码语言:javascript
复制
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会在幕后为您做这件事

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66583114

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档