【问题标题】:Authenticating for spotify web api not working验证 spotify web api 不起作用
【发布时间】:2015-08-06 07:01:24
【问题描述】:

我正在使用 spotify web api 编写一个应用程序供个人使用。它是一个 node.js 应用程序。我调用了accounts.spotify.com/authorize 端点并被重定向到spotify 登录,但我无法使用Facebook 或spotify 用户名/密码登录。

当我尝试通过 Facebook 登录时,我收到以下错误:“App Not Setup: This app is still in development mode, and you don't access to it. switch to a registered test user or ask an app管理员权限。”当我尝试使用 spotify 用户名/密码登录时,我收到以下错误:“糟糕!出了点问题,请重试或查看我们的帮助区域”

这里是代码。除了重定向到 spotify 登录之外,它目前并没有做太多事情。我编辑了 client_id 和重定向 URL。如果我直接在浏览器中输入重定向 URL,则可以访问它。我相信,既然我得到了 Spotify 登录页面,我就在正确的范围内,但可能错过了应用程序设置或代码中的某些内容。

谁能告诉我如何克服这个错误?谢谢。

var request = require('request');
function SpotifyLogin(req,res)
{
    var options =
    {
        url: 'http://accounts.spotify.com/authorize/?client_id=<redacted>&response_type=code&redirect_uri=<redacted>&scope=user-read-private&state=34fFs29kd09&show_dialog=true',
        followAllRedirects: true,
        followRedirect: true
    };

    request(options, function(error, response, body)
    {
        res.send(body);
        console.log(body);
        console.log(response.toJSON());
    }).on('error', function(e) {
        res.setHeader('Content-Type', 'text/html');
        res.send("<html><body>"+ e.message +"</body></html>");
        console.log("Got error: " + e.message);
    });

}

【问题讨论】:

  • 这在 URL 中是否正确? &lt;redacted&gt;
  • 不,我取出了真正的client_id和redirect_uri,并用“已编辑”的文字替换了它们。
  • 您能否尝试/authorize URL 并通过在浏览器中打开应用程序来授权您的应用程序?如果您在登录后出现错误,则应在开发者控制台中显示错误描述。 (检查网络和/或控制台。)
  • 一个常见的问题是授权时使用的重定向 URI 没有添加到应用程序中,所以我会仔细检查。
  • 当我直接在浏览器中输入带有所有参数的 /authorize URL 并在浏览器中完成手动步骤时,spotify 会重定向到指定的 URL。该应用程序似乎在 spotify 上设置正确。在不起作用的情况下,当浏览器在我的服务器上点击一个 URL 并且我发出了对 spotify 的请求时,我认为当我将来自 spotify 的初始响应发送回浏览器时我做错了。谢谢你的帮助。当我从我的服务器发送 spotify 请求时,我仍在试图弄清楚为什么我无法使其工作。有什么想法吗?

标签: spotify


【解决方案1】:

感谢在评论中提出建议的 jooon,如果我的服务器返回一个页面,该页面仅使用正确的参数将浏览器重定向到 https:/accounts.spotify.com/authenticate,则身份验证流程可以正常工作,从而导致 spotify调用我的回调 URL。

这里是硬编码的 spotify URL,我的 client_id 和 redirect_url 被隐藏了。

function SpotifyLogin(req, res)
{
    res.writeHead(302, {
        'Location': encodeURI("https://accounts.spotify.com/authorize/?client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&response_type=code&redirect_uri=http://xxxxxxx/callback/&scope=playlist-read-private playlist-read-collaborative playlist-modify-public playlist-modify-private streaming user-follow-modify user-follow-read user-library-read user-library-modify user-read-private user-read-birthdate user-read-email&state=34fFs29kd09&show_dialog=true")
    });
    res.send();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-05
    • 1970-01-01
    • 2017-04-13
    • 2015-03-01
    相关资源
    最近更新 更多