我正在尝试使用CSS Tricks方法获取Twitter Feed:
http://css-tricks.com/build-your-own-social-home/
进行一些改动。在Dreamweaver的实时预览中,一切正常,但是当它上传到服务器时,没有任何内容出现。我已经对其他问题进行了一些搜索,并且无法直接提出与我的问题有关的任何问题
JQuery的:
$(document).ready(function(){
$.getJSON('https://api.twitter.com/1/statuses/user_timeline.json?callback=?include_entities=true&user_id=913166730&count=5', function(data){
$.each(data, function(index, item){
$('#news').append('<div class="story"><h3 style="margin:0px;"><a style="color:#000; text-decoration:none;" href="http://twitter.com/TheHopperLane" title="The Hopper Lane">@Thehopperlane</a></h3><p>' + item.text.linkify() + '</p><p style="font-size:12px;">' + relative_time(item.created_at) + '</p></div>');
});
});
function relative_time(time_value) {
var values = time_value.split(" ");
time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
var parsed_date = Date.parse(time_value);
var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
delta = delta + (relative_to.getTimezoneOffset() * 60);
var r = '';
if (delta < 60) {
r = 'a minute ago';
} else if(delta < 120) {
r = 'couple of minutes ago';
} else if(delta < (45*60)) {
r = (parseInt(delta / 60)).toString() + ' minutes ago';
} else if(delta < (90*60)) {
r = 'an hour ago';
} else if(delta < (24*60*60)) {
r = '' + (parseInt(delta / 3600)).toString() + ' hours ago';
} else if(delta < (48*60*60)) {
r = '1 day ago';
} else {
r = (parseInt(delta / 86400)).toString() + ' days ago';
}
return r;
}
String.prototype.linkify = function() {
return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) {
return m.link(m);
}).replace(/\B#([_a-z0-9]+)/ig, function(hashtag) {
return '<a href="http://twitter.com/search?q=%23'+hashtag.substring(1)+'">'+hashtag+'</a>';
}).replace(/\B@([_a-z0-9]+)/ig, function(screenname) {
return '<a href="http://twitter.com/'+screenname+'">'+screenname+'</a>';
});
};
});
HTML
<div id="news">
<h2>Latest News</h2>
我们将非常感谢任何建议,如有必要,我可以提供相关网站的链接
编辑:似乎一切都只是因为以下错误!
"XMLHttpRequest cannot load https://api.twitter.com/1/statuses/user_timeline.json?callback=?include_entities=true&user_id=913166730&count=5. Origin http://thehopperlane.co.uk is not allowed by Access-Control-Allow-Origin."
我简直不敢相信我没有赶上这个!但是,据我所知,我已将该问题保持打开状态,因为在本网站上尚未解决。人们提到包括回调=?并且使用JSONP而不仅仅是JSON,但是这些修复似乎不再起作用(注意答案的最后评论here