用spotify显示权限


我正在使用spotify-web-api-node授权用户,以便我可以创建和修改用户播放列表。
该应用程序正常工作。 用户可以将其定向到Spotify帐户页面,获得授权,然后重定向到我的应用程序。
但是在Spotify授权页面上时,它不会显示应用程序所要求的权限(范围) 。 我猜它应该看起来像Spotify网站上显示的图像。 我不太确定它是否代表我的代码不完整,或者在使用spotify-web-api-node时Spotify授权页面可能存在问题。

编辑

app.js

 var SpotifyWebApi = require('spotify-web-api-node');
 var http = require('http'),
 fs = require('fs'),
 index = fs.readFileSync(__dirname + '/index.html');

 // Send index.html to all requests
 var app = http.createServer(function(req, res) {
 res.writeHead(200, {'Content-Type': 'text/html'});
 res.end(index);
 });

var scopes = ['playlist-modify-public', 'playlist-modify-private'],
redirectUri = 'http://localhost:3000',
clientId = '',
clientSecret = '',
state = 'some-state-of-my-choice';

// Setting credentials can be done in the wrapper's constructor.
var spotifyApi = new SpotifyWebApi({
redirectUri : redirectUri,
clientId : clientId,
clientSecret : clientSecret
});

// Create the authorization URL
var authorizeURL = spotifyApi.createAuthorizeURL(scopes, state);
console.log(authorizeURL);


// Socket.io server listens to our app
var io = require('socket.io').listen(app);
io.sockets.on('connection', function (socket){
io.sockets.emit('url',{value:authorizeURL});

//once code is extracted from client-side get tokens
socket.on('code', function(data){
  var code = data.x;

   // get tokens
  spotifyApi.authorizationCodeGrant(code)
    .then(function(data) {

    console.log('The token expires in ' + data['expires_in']);
    console.log('The access token is ' + data['access_token']);
    console.log('The refresh token is ' + data['refresh_token']);
    console.log(code);
    }, function(err) {
        console.log('Something went wrong with getting Auth tokens !', err);
      });
     });
   });app.listen(3000);

HTML

<body>
  <a><button>Authorize</button></a>
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  <script src='//localhost:3000/socket.io/socket.io.js'></script>
    <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.1.min.js"></script>')</script>

   <script>
   function getParameterByName(name) {
    name = name.replace(/[[]/, "[").replace(/[]]/, "]");
    var regex = new RegExp("[?&]" + name + "=([^&#]*)"),
    results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/+/g, " "));
    }

      $( document ).ready(function() {
        var socket = io.connect('//localhost:3000');
        var code = getParameterByName('code');
            socket.emit('code', { x: code});
            socket.on('url', function(data) {
             $('a').attr('href',data.value);
            });
      });
    </script>

</body>

有一个测试检查AuthorizeURL是否包含范围。 确保你发送的范围在一个数组中。 你的代码应该看起来像这样(显然,随着作用域,redirectUri,clientId和state更改为你的应用程序的值)

var scopes = ['user-read-private', 'user-read-email'],
redirectUri = 'https://example.com/callback',
clientId = '5fe01282e44241328a84e7c5cc169165',
state = 'some-state-of-my-choice';

var api = new SpotifyWebApi({
    clientId : clientId,
    redirectUri : redirectUri
});

var authorizeURL = api.createAuthorizeURL(scopes, state);
console.log(authorizeURL); // "https://accounts.spotify.com/authorize?client_id=5fe01282e44241328a84e7c5cc169165&response_type=code&redirect_uri=https://example.com/callback&scope=user-read-private%20user-read-email&state=some-state-of-my-choice"

希望这可以帮助! 如果没有,请在您的问题中包含您的代码。

链接地址: http://www.djcxy.com/p/55671.html

上一篇: Displaying permissions with spotify

下一篇: Spotify Web API client scope not working