jQuery: JSON api is not working
I'm having a issue to get my twitter status to work properly. If you go to http://www.nascarspeedpark.com/nc.aspx and look at the right side of the page you'll see latest tweets. The link next to the Avatar is not working.
The code looks right to me. It seems as though the code is calling the twitter api properly.
function relative_time(date) {
var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
var delta = parseInt((relative_to.getTime() - date) / 1000, 10);
var r = '';
if (delta < 60) {
r = delta + ' seconds ago';
} else if(delta < 120) {
r = 'a minute ago';
} else if(delta < (45*60)) {
r = (parseInt(delta / 60, 10)).toString() + ' minutes ago';
} else if(delta < (2*60*60)) {
r = 'an hour ago';
} else if(delta < (24*60*60)) {
r = '' + (parseInt(delta / 3600, 10)).toString() + ' hours ago';
} else if(delta < (48*60*60)) {
r = 'a day ago';
} else {
r = (parseInt(delta / 86400, 10)).toString() + ' days ago';
}
return 'about ' + r;
}
function build_url() {
var proto = ('https:' == document.location.protocol ? 'https:' : 'http:');
var count = (s.fetch === null) ? s.count : s.fetch;
if (s.list) {
return proto+"//"+s.twitter_api_url+"/1/"+s.username[0]+"/lists/"+s.list+"/statuses.json?per_page="+count+"&callback=?";
} else if (s.favorites) {
return proto+"//"+s.twitter_api_url+"/favorites/"+s.username[0]+".json?count="+s.count+"&callback=?";
} else if (s.query === null && s.username.length == 1) {
return proto+'//'+s.tw开发者_如何学Citter_api_url+'/1/statuses/user_timeline.json?screen_name='+s.username[0]+'&count='+count+(s.retweets ? '&include_rts=1' : '')+'&callback=?';
} else {
var query = (s.query || 'from:'+s.username.join(' OR from:'));
return proto+'//'+s.twitter_search_url+'/search.json?&q='+encodeURIComponent(query)+'&rpp='+count+'&callback=?';
}
}
As far as I can tell, the problem is that your script is getting (and thus linking to) the wrong tweet id. For example, the latest tweet id is 53522381905461248
but for some reason, your script gets the value 53522381905461250
through item.id
. The JSON response from twitter seems to be alright but the parsed JSON object seems to get the wrong value for id
.
Where you create the HTML for the relative time linked to the Twitter status page, Try using the id_str
property instead:
var date = '<span class="tweet_time"><a href="http://twitter.com/'+from_user+'/statuses/'+item.id_str+'" title="view tweet on twitter">'+relative_time(item.created_at)+'</a></span>';
精彩评论