0
我試圖從藝術家處獲得第一個頂級預覽網址,但每次我搜索時都會返回一個破碎的json。我可以將它解析爲一個字符串來獲取我需要的內容,但是json會更容易。這裏是我的代碼:Spotify API頂級曲目中斷
const https = require('https');
var open = require('open')
function songError(){
console.log('There was some kind of error fetching your artist ;(');
}
function getTopSong(p_id){
https.get('https://api.spotify.com/v1/artists/'+p_id+'/top-tracks?country=BR', function(res){
res.on("data", function(chunk){
var json = JSON.parse(chunk.toString('utf8'));
console.log(json);
});
});
}
function getArtistID(p_name) {
https.get('https://api.spotify.com/v1/search?q='+encodeURI(p_name)+'&type=artist', function(res){
res.on("data", function(chunk) {
var json = JSON.parse(chunk.toString('utf8'));
if(json['artists']['items'][0]['id'] != undefined || json['artists']['items'][0]['id'] != null){
console.log('id: ',json['artists']['items'][0]['id']);
getTopSong(json['artists']['items'][0]['id']);
}else
{
songError();
}
});
});
}
getArtistID("rage against the machine");
似乎是在管線329錯誤:
undefined:329
"available_markets" : [ "AR", "AU", "AT", "BE", "BO", "BR", "BG", "CA", "CL", "CO", "CR", "CY", "CZ", "DK", "DO", "DE", "EC", "EE", "SV", "FI", "FR", "GR", "
我的問題是,我是不是做錯了什麼或者是不是真的壞了? 謝謝!
就是這樣,我忘了將它連接在一起,愚蠢的錯誤!謝謝! –
我剛剛意識到它可能與服務器的分塊傳輸編碼無關。無論如何,api可能會將身體分割爲塊,因此您可以下載千兆字節而不必將所有內容都讀入內存。 – jooon