1

这是我正在使用的代码,但它已停止工作。找人帮我解决这个问题,因为我对此知之甚少。

// JQuery Twitter Feed. Coded by www.tom-elliott.net (2012) and modified from https://twitter.com/javascripts/blogger.js
var p = jQuery.noConflict();
p(document).ready(function () {
    var twitterprofile = "waateanews";
    var hidereplies = true;
    var showretweets = true;
    var showtweetlinks = true;
    var displayLimit = 3;

    p.getJSON('https://api.twitter.com/1/statuses/user_timeline/'+twitterprofile+'.json?include_rts='+showretweets+'&exclude_replies='+hidereplies+'&count=30&callback=?',
        function(feeds) {
            var feedHTML = '';
            var displayCounter = 1;

            for (var i=0; i<feeds.length; i++) {
                var username = feeds[i].user.screen_name;
                var profileimage = feeds[i].user.profile_image_url_https;
                var status = feeds[i].text;

                if ((feeds[i].text.length > 1) && (displayCounter <= displayLimit)) {
                    if (showtweetlinks == true) {
                        status = addlinks(status);
                    }

                    if (displayCounter == 1) {
                        //feedHTML += '<h1><a href="https://twitter.com/'+twitterprofile+'" target="_blank">@'+twitterprofile+'</a> on Twitter</h1>';
                    }

                    feedHTML += '<div class="twitter-article">';
                    feedHTML += '<div class="twitter-pic"><img src="'+profileimage+'"images/twitter-feed-icon.png" width="42" height="42" alt="twitter icon" /></div>';
                    feedHTML += '<div class="twitter-text"><p>'+status+'<br/><span class="tweet-time">'+relative_time(feeds[i].created_at)+'</span></p></div>';
                    feedHTML += '</div>';
                    displayCounter++;
                }
            }

            p('#twitter-feed').html(feedHTML);
    });

    function addlinks(data) {
        //Add link to all http:// links within tweets
        data = data.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
            return '<a href="'+url+'" target="_blank">'+url+'</a>';
        });

        //Add link to @usernames used within tweets
        data = data.replace(/\B@([_a-z0-9]+)/ig, function(reply) {
            return '<a href="http://twitter.com/'+reply.substring(1)+'" style="font-weight:lighter;" target="_blank">'+reply.charAt(0)+reply.substring(1)+'</a>';
        });
        return data;
    }

    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);

      if (delta < 60) {
        return 'less than a minute ago';
      } else if(delta < 120) {
        return 'about a minute ago';
      } else if(delta < (60*60)) {
        return (parseInt(delta / 60)).toString() + ' minutes ago';
      } else if(delta < (120*60)) {
        return 'about an hour ago';
      } else if(delta < (24*60*60)) {
        return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
      } else if(delta < (48*60*60)) {
        return '1 day ago';
      } else {
        return (parseInt(delta / 86400)).toString() + ' days ago';
      }
    }

});
</script>
<div id="twitter-feed"></div>
<div id="twitter_footer"><a href="https://twitter.com/waateanews">Follow us on twitter</a></div>
4

1 回答 1

3

Twitter 已停用 API v1。详情在这里。您将不得不重写代码以使用 oAuth 或使用一些现成的脚本。我会让你弄清楚的。

于 2013-06-18T02:58:52.220 回答