Twitter Feed Not Pulling

resolved (7 posts) (2 voices)

  1. I placed this code at the end of my page to try and pull the twitter feed into the footer. It is not showing. Here is the code:

    <style type = 'text/css'>
     .webtreats_twitter_widget ul a { display: inline !important; }
     .webtreats_twitter_widget ul li { margin-bottom: 10px !important; }
     </style>
     <script type = 'text/javascript'>
    
    function grabTweets(twitters) {
      var statusHTML = [];
      for (var i=0; i<twitters.length; i++){
        var username = twitters[i].user.screen_name;
        var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
          return '<a href="'+url+'">'+url+'</a>';
        }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
          return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
        });
        statusHTML.push('
    
    <li><a href="http://twitter.com/'+username+'/statuses/'+twitters[i].id_str+'">'+ status + '' + relative_time(twitters[i].created_at)+'</a></li>
    ');
      }
      jQuery('.webtreats_twitter_widget ul').html(statusHTML.join(''));
    }
    
    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';
      }
    }
    
    jQuery(document).ready(function() {
        var username = 'CAandLL';
        jQuery.getScript('http://twitter.com/statuses/user_timeline/' + username + '.json?callback=grabTweets&count=5');
    });
    
    </script>
    
    </body>

    here is the page that I am trying to put it in:

    http://chedev.iu.edu/IupuiCal/

    Posted 1 year ago #
  2. Elliott
    Support

    Hello ericagilbert,

    On this part here,

    statusHTML.push('
    
    <li><a href="http://twitter.com/'+username+'/statuses/'+twitters[i].id_str+'">'+ status + '' + relative_time(twitters[i].created_at)+'</a></li>
    ');

    Make sure it is all on one line like so,

    statusHTML.push('<li><a href="http://twitter.com/'+username+'/statuses/'+twitters[i].id_str+'">'+ status + '' + relative_time(twitters[i].created_at)+'</a></li>');

    Let us know if that fixes it for you.

    Posted 1 year ago #
  3. That did not work. I am listing the div class as this:
    <div class="twitter-widget.webtreats_twitter_widget ul li a">

    Is that incorrect?

    Posted 1 year ago #
  4. Elliott
    Support

    Your not getting any javascript errors anymore but your div needs to look like this,

    <div class="webtreats_twitter_widget">

    Posted 1 year ago #
  5. Thanks so much, it is now working.

    There is one thing I was hoping to change. The time-stamp for each tweet is running right into the text of the tweet. How do I create a space, or perhaps insert a ~ to ensure it reads well?

    Thanks,
    Erica

    Posted 1 year ago #
  6. Elliott
    Support

    Here is the part where the actual tweet gets displayed,

    statusHTML.push('<li><a href="http://twitter.com/'+username+'/statuses/'+twitters[i].id_str+'">'+ status + '' + relative_time(twitters[i].created_at)+'</a></li>');

    If you want to add a ~ inbetween the message and the time then change it like this,

    statusHTML.push('<li><a href="http://twitter.com/'+username+'/statuses/'+twitters[i].id_str+'">'+ status + ' ~ ' + relative_time(twitters[i].created_at)+'</a></li>');

    Let us know if that is what you were wanting.

    Posted 1 year ago #
  7. Yes, it is.
    Thanks so much.

    Best,
    Erica

    Posted 1 year ago #

Reply

You must log in to post.

Construct WordPress Theme
Construct wordpress theme
Myriad WordPress Theme
Myriad wordpress theme
Method WordPress Theme
Method wordpress theme
Fusion WordPress Theme
Fusion wordpress theme
Elegance WordPress Theme
Elegance wordpress theme
Echelon WordPress Theme
Echelon wordpress theme
Dejavu WordPress Theme
Dejavu wordpress theme
Modular WordPress Theme
Modular wordpress theme