盡管我檢查了文檔(如果我犯了拼寫錯誤),但我仍然遇到相同的錯誤。我將我的代碼與視頻中共享的代碼進行了比較,它們看起來完全相同,但我不斷收到此錯誤:{?"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>
Spotify API:錯誤 401,“未提供令牌”
江戶川亂折騰
2023-10-14 16:46:00