尽管我检查了文档(如果我犯了拼写错误),但我仍然遇到相同的错误。我将我的代码与视频中共享的代码进行了比较,它们看起来完全相同,但我不断收到此错误:{ "error": { "status": 401, "message": "No token provided" }}作为参考,我的js在这里const app = {};app.apiUrl = 'https://api.spotify.com/v1';//Allow user to enter some namesapp.events = function() { $('form').on('submit', function(e){ e.preventDefault(); let artists = $('input[type=search]').val(); artists = artists.split(','); let search = artists.map(artistName => app.searchArtist(artistName)); $.when(...search) .then((...results) => { console.log(results); }); });};//Go to spotify to get the artist nameapp.searchArtist = (artistName) => $.ajax({ url: `${app.apiUrl}/search`, method:'GET', dataType: 'json', data: { q: artistName, type: 'artist' }});//Using the IDs, get the albums//Get tracks//Build playlistapp.init = function() { app.events();};$(app.init);我知道该视频是 4 年前发布的,但我也检查了端点的文档,自 4 年前以来似乎没有任何变化。进一步参考,我的 HTML 代码:<body> <main class="main-container"> <section> <div class="form"> <img src="images/note.svg" alt=""> <form action=""> <input type="search" value="muse,ghost"> <input type="submit" value="Create"> </form> <p>Icon created by unlimicon from the Noun Project</p> </div> <div class="playlist"> <div class="loader"> <div class="inner-circle"></div> </div> </div> </section> </main> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script src="script.js"></script></body>
3 回答

慕斯709654
TA贡献1840条经验 获得超5个赞

斯蒂芬大帝
TA贡献1827条经验 获得超8个赞
您是否已经定义了 Spotify 访问令牌?
https://developer.spotify.com/
app.searchArtist = (artistName) => $.ajax({
url: `${app.apiUrl}/search`,
method:'GET',
dataType: 'json',
data: {
q: artistName,
type: 'artist'
},
headers: {
"Authorization": `Bearer ${yourToken}`
}
});
添加回答
举报
0/150
提交
取消