2017-07-03 71 views
1

我正在使用Spotify Web Api的jscript製作應用程序。我使用請求模塊從node.js上的app.js調用,我設法在播放器暫停後使其播放,但它不會加載context_uri或來自uris陣列。我儘可能地嘗試了json的各種格式,並且無法播放選定的曲目或專輯。這裏是我的代碼:Spotify Web Api - 開始/恢復用戶的播放

request({ 
    method: 'PUT', 
    uri: 'https://api.spotify.com/v1/me/player/play', 
    headers:{ 
     Authorization: 'Bearer ' + access_token 
    }, 
    data:{ 
     "context_uri": "spotify:album:5ht7ItJgpBH7W6vJ5BqpPr" 
    } 
}, function (error, response, body) { 
    console.log(body); 
}); 

所以我並不在發送請求得到任何錯誤,但它不改變對玩家在context_uri發送的歌當前歌曲。我不確定天氣我的格式是錯誤的還是別的,但我會感謝幫助,謝謝。

+0

我有同樣的問題[鏈接到我的問題](https://stackoverflow.com/questions/47480907/spotify-web-api-v1-me-player-play-not-playing-specified-uri) 。你最終搞清楚了嗎? –

回答

0

試試這個:

var options = { 
    url: 'https://api.spotify.com/v1/me/player/play', 
    headers: { 
     'Authorization': 'Bearer ' + access_token, 
     'Accept': 'application/json', 
     'Content-Type': 'application/json' 
    }, 
    json: { "context_uri": uri } 
    }; 


    request.put(options, function(error, response, body) { 
    etc 
    } 

換句話說,使用JSON,而不是數據。

相關問題