2017-06-08 64 views
0

我正在尝试使用简单的GET请求访问last.fm的API。我发现的最好的NPM库是由feross最后一个。问题是我的请求保持超时,我没有得到任何错误。流星造成这种情况吗?last.fm GET请求超时流星

我的请求URL是: https://ws.audioscrobbler.com:3000/2.0/?method=artist.getInfo&artist=cher&autocorrect=1&api_key=MY_API_KEY&format=json

这里是代码。

import LastFM from 'last-fm'; 

const lastfm = new LastFM("MY_API_KEY", {userAgent: "buildsmoothie"}) 

export const ArtistCheck =() => { 
    lastfm.artistInfo({ name: "cher" }, (err, data) => { 
    if (err) console.log(err) 
    else console.log(data) 
    }) 
} 

然后我把它在这里的另一个组件:

artistGateCheck(e){ 
    e.preventDefault(); 
     ArtistCheck(); 
    } 

回答

2

我已经删除了端口:3000和它的作品,因为它应该。使用后续网址:

https://ws.audioscrobbler.com/2.0/?method=artist.getInfo&artist=cher&autocorrect=1&api_key=MY_API_KEY&format=json

+0

谢谢!但是你知道为什么我的本地主机端口显示在api调用中吗? – John

+0

不确定。在feross的last-fm库中,index.js文件有一个名为'const urlBase'的变量,确保将正确的url设置为https:// ws.audioscrobbler.com/2.0 /' –

+0

它明天,看看是否停止了这个问题,谢谢你帮我找到它。 – John