亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Spotify API:錯誤 401,“未提供令牌”

Spotify API:錯誤 401,“未提供令牌”

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

轉至https://developer.spotify.com/console/get-search-item/以生成 OAuth 令牌,并在 API 調用中使用相同的令牌作為授權承載令牌。

https://img1.sycdn.imooc.com/652a55950001e36924851286.jpg


查看完整回答
反對 回復 2023-10-14
?
斯蒂芬大帝

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}`

    }

});


查看完整回答
反對 回復 2023-10-14
?
大話西游666

TA貢獻1817條經驗 獲得超14個贊

您似乎丟失了 API 密鑰或未正確傳遞它。



查看完整回答
反對 回復 2023-10-14
  • 3 回答
  • 0 關注
  • 211 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號