<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title>Twitter feed</title>
<style>
body { width: 600px; margin: auto; }
ul { list-style: none; }
li { padding-bottom: 1em; }
img { float: left; padding-right: 1em; }
a { text-decoration: none; color: #333; }
</style>
</head>
<body>
<ul id="biebster-tweets">
<script id="tweets-template" type="text/x-handlebars-template">
{{#each this}}
<li>
<img src="{{thumb}}" alt="{{author}}">
<p><a href="{{url}}">{{tweet}}</a></p>
</li>
{{/each}}
</script>
</ul>
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="http://cloud.github.com/downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js"></script> -->
<script type="text/javascript" src="jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="handlebars-v3.0.3.js"></script>
<script>
(function() {
var Twitter = {
init: function( config ) {
this.url = 'http://search.twitter.com/search.json?q=' + config.query + '&callback=?';
this.template = config.template;
this.container = config.container;
this.fetch();
},
attachTemplate: function() {
var template = Handlebars.compile( this.template );
this.container.append( template( this.tweets ) );
},
fetch: function() {
var self = this;
$.getJSON( this.url, function( data ) {
self.tweets = $.map( data.results, function( tweet ) {
return {
author: tweet.from_user,
tweet: tweet.text,
thumb: tweet.profile_image_url,
url: 'http://twitter.com/' + tweet.from_user + '/status/' + tweet.id_str
};
});
// For future lessons, research $.deferred, viewers. :)
self.attachTemplate();
});
}
};
Twitter.init({
template: $('#tweets-template').html(),
container: $('#biebster-tweets'),
query: 'tutspluspremium'
});
})();
</script>
</body>
</html>
此代码取自jquery的视频教程。当作者使用此代码时,它已成功运行。但是当我尝试使用此代码时,此处显示错误 - &gt;
this.url = 'http://search.twitter.com/search.json?q=' + config.query + '&callback=?';
基本上,错误在url链接中。我该如何解决?任何人都帮帮我..
答案 0 :(得分:0)
您尝试使用不再有效的Twitter API版本1。您需要更新代码才能使用v1.1。