在 JavaScript 中使用 last.fm API
我对网络开发的经验很少。我对 HTML 有一点经验,现在正在学习 JavaScript。我使用 Java 的 last.fm 库创建了一个 Java 程序。我能够获取用户信息、艺术家信息和场地信息。现在我想尝试在网页中执行此操作,这就是我的问题发生的地方。
我正在使用此处给出的 javascript last.fm api http://github.com/ fxb/javascript-last.fm-api 我已经下载了所有 .js 文件,它们与我的 .htm 文件位于同一目录中。
这是我到目前为止的代码。
<html>
<body>
<script type="text/javascript" src="lastfm.api.md5.js"></script>
<script type="text/javascript" src="lastfm.api.js"></script>
<script type="text/javascript" src="lastfm.api.cache.js"></script>
<script type="text/javascript">
var cache = new LastFMCache();
var lastfm = new LastFM({
apiKey : 'c9946d11aaaaaaaaaaaaaaaaaaaaaaaace',
apiSecret : '9dabf9aaaaaaaaaaaaaaaaxxx11ec3c7a993',
cache : cache
});
lastfm.artist.getInfo({artist: 'The xx'}, {success: function(data){
/* Use Data */
}, error: function(code, message){
/* Show error message. */
}});
</script>
</body>
</html>
我已经深入研究了包含的 .js 文件,试图了解发生了什么。因此,在初始化 Lastfm 时,我传入了一些具有关联值的对象,然后将其应用于 Lastfm。如果我尝试通过 document.write(lastfm.apiKey) 访问它们,我会得到一个未定义的值,我不太明白。
我还看到我正在调用 getInfo 并传入“The xx”以及后面的所有内容。我不明白如何使用我认为作为 JSON 响应返回的数据。如何打印与该艺术家相关的个人简介?
I have very little experience with web development. I have a little experience with HTML and I am learning JavaScript right now. I created a program in Java using a a last.fm library for Java. I was able to get user information, artist information, and venue information. Now I want to try and do that in a webpage, which is where my problem occurs.
I'm using the javascript last.fm api given here http://github.com/fxb/javascript-last.fm-api
I've downloaded all the .js files and they are in the same directory as my .htm file.
This is my code so far.
<html>
<body>
<script type="text/javascript" src="lastfm.api.md5.js"></script>
<script type="text/javascript" src="lastfm.api.js"></script>
<script type="text/javascript" src="lastfm.api.cache.js"></script>
<script type="text/javascript">
var cache = new LastFMCache();
var lastfm = new LastFM({
apiKey : 'c9946d11aaaaaaaaaaaaaaaaaaaaaaaace',
apiSecret : '9dabf9aaaaaaaaaaaaaaaaxxx11ec3c7a993',
cache : cache
});
lastfm.artist.getInfo({artist: 'The xx'}, {success: function(data){
/* Use Data */
}, error: function(code, message){
/* Show error message. */
}});
</script>
</body>
</html>
I've dug around in the included .js files to try and understand what is going on. So on my initialization of lastfm, I am passing in some objects with associated values, which are then applied to lastfm. If I try and access them through document.write(lastfm.apiKey) I get an undefined value, which I don't really understand.
Also I see that I am calling getInfo and passing in 'The xx' and everything that follows. I don't understand how to use that Data that I believe is returned as a JSON response. How can I print the bio that is associated with that artist?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应该放在您编写的 /* Use Data */ 位置的代码将引用诸如
data.bio
之类的项目。尝试alert(data)
看看里面有什么。我还强烈建议使用 JavaScript 调试控制台(例如 FireBug),以便真正了解发生了什么。
the code that should go where you have written /* Use Data */ will refer to items such as
data.bio
. Tryalert(data)
to see what's in there.I would also highly recommend using a JavaScript debugging console such as FireBug in order to really see what's going on.
我刚刚用过这个,是的。您只需要成功地 console.log(data) 即可获取有关从上一个调频传回的数据的信息
i just used this, and yeah. you just need to console.log(data) in the success to get info about the data that is being passed back from last fm