首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法从Spotify API获取访问令牌

无法从Spotify API获取访问令牌
EN

Stack Overflow用户
提问于 2017-08-01 20:18:43
回答 1查看 896关注 0票数 0

我尝试使用Request模块向https://accounts.spotify.com/api/token发出POST请求,以获取访问令牌。我已经用我的Spotify dev帐户注册了重定向URI。这是我的特快/redirect路线。

代码语言:javascript
运行
复制
const Request = require('request');

module.exports = (req, res) => {
  const data = {
    grant_type: 'authorization_code',
    code: req.query.code,
    redirect_uri: 'http://localhost:3000/redirect',
    client_id: process.env.SPOTIFY_ID,
    client_secret: process.env.SPOTIFY_SECRET
  }

  const options = {
    method: 'POST',
    url: 'https://accounts.spotify.com/api/token',
    json: true,
    body: data
  }

  Request(options, (error, response, body) => {
    if (error) return console.log(error);
    res.end(body);
  });
};

有人能看到这里可能出了什么问题吗?每次我得到的都是一个不起眼的“糟糕!出了点问题”的错误页面。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-01 22:26:35

数据参数必须作为表单数据传递:

代码语言:javascript
运行
复制
const options = {
  method: 'POST',
  url: 'https://accounts.spotify.com/api/token',
  json: true,
  form: data
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45437593

复制
相关文章

相似问题

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