【问题标题】:getting songs from tinysong从 tinysong 获取歌曲
【发布时间】:2012-08-05 23:30:11
【问题描述】:

我不想通过从 Grooveshark 获取歌曲的 tinysong API 获取歌曲列表,我正在通过 $.ajax 获取歌曲列表,到目前为止我得到了这个:

$.ajax({
    url : 'http://tinysong.com/s/Beethoven?format=json&key='+key,
    type : 'get',
    dataType : 'jsonp',
    succes : function(response){
        console.log(response);
        $('.content').append(response);
    },
    error: function(error){
        console.warn('ERROR');
        console.warn(error);
    }
});

key 是他们分配给我的 API 密钥。我收到以下错误:

资源解释为脚本,但使用 MIME 类型 text/html 传输:“http://tinysong.com/s/Beethoven?format=json&key=HERE_IS_MY_KEY&callback=jQuery172021696692402474582_1344209008518&_=1344209008523”。

但是,如果我访问该网址,我会得到如下打印结果:

[{"Url":"http://tinysong.com/Aoxo","SongID":25802452,"SongName":"A 大调第七交响曲 Op. 92: Allegretto","ArtistID" :1833,"ArtistName":"Beethoven","AlbumID":4497124,"AlbumName":"Beethoven: 9 Symphonien, Ouvert\u00fcren (1 of 6), Berstein, Leonard"},{"Url":"http: //tinysong.com/jh4X","SongID":2909282,"SongName":"降E大调第五钢琴协奏曲 op. 73 'Emperor'","ArtistID":1833,"ArtistName":"Beethoven" ,"AlbumID":268605,"AlbumName":"贝多芬之最"},{"Url":"http://tinysong.com/JhLy","SongID":31825464,"SongName":"贝多芬:钢琴F小调第23奏鸣曲,作品57,\"热情\"","ArtistID":1833,"ArtistName":"Beethoven","AlbumID":4913792,"AlbumName":"Beethoven's Greatest Hits"},{ "Url":"http://tinysong.com/6Jk1","SongID":4925300,"SongName":"Beethoven #4: Adagio","ArtistID":1833,"ArtistName":"Beethoven","AlbumID ":842118,"AlbumName":"Beethoven: Symphonies Nos. 7 & 4"},{"Url":"http://tinysong.com/gGW0","SongID":11896153,"SongName":"F\ u00fcr Elise","ArtistID":1833,"ArtistName" :"Beethoven","AlbumID":2087629,"AlbumName":"Beethoven and the Sea"}]

如何将这些信息传递给我的 javascript?

【问题讨论】:

    标签: javascript jquery json grooveshark


    【解决方案1】:

    您得到的“错误”只是一个警告。 Tinysong 使用错误的内容类型(“text/html”)传输 JSON 响应。您可以通过curl 验证这一点,例如:

    curl --head http://tinysong.com/s/Beethoven\?format\=json\&key\=<your key>
    

    可以在answer 中找到您的脚本无法正常工作的解释以及问题的解决方案(请同时阅读 cmets)。

    也许您应该联系 Tinysong,报告有关内容类型的错误并请求 JSONP 支持。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-30
      • 1970-01-01
      • 2017-09-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多