Link to home
Create AccountLog in
Avatar of epichero22
epichero22Flag for United States of America

asked on

Twitter widget isn't working

Hi, take a look at my website, and if you scroll down, you'll see a widget for "Recent Tweets," which used to load my tweets but has stopped:

Edit: http://www.redalertconsulting.com

Here is the code for "my-twitter-widget.php"...I don't know if Twitter updated their API or not, and it's not working as a result:

<?php
// =============================== My Twitter Wiget ======================================
class MY_TwitterWidget extends WP_Widget {
    /** constructor */
    function MY_TwitterWidget() {
        parent::WP_Widget(false, $name = 'My - Twitter');
    }
	
	
  /** @see WP_Widget::widget */
    function widget($args, $instance) {		
        extract( $args );
        $title = apply_filters('widget_title', $instance['title']);
		$twitter_name = apply_filters('twitter_name', $instance['twitter_name']);
		$amount = apply_filters('twitter_twitts_amount', $instance['twitts_amount']);
		$suf = rand(100000,999999);		
        ?>
        <?php echo $before_widget; ?>
			
<div id="twitter-<?php echo $suf; ?>" class="twitter"></div>
	<script>
      jQuery("#twitter-<?php echo $suf; ?>").getTwitter({
        userName: "<?php echo $twitter_name; ?>",
        numTweets: <?php echo $amount; ?>,
        loaderText: "Loading tweets...",
        slideIn: true,
        showHeading: true,
				beforeHeading: "<?php echo $before_title; ?>",
				afterHeading: "<?php echo $after_title; ?>",
        headingText: "<?php echo $title; ?>",
        id:"#twitter-<?php echo $suf; ?>",
        showProfileLink: false
      });
  </script>      
    
   						<?php wp_reset_query(); ?>
								
              <?php echo $after_widget; ?>
			 
        <?php
    }

    /** @see WP_Widget::update */
    function update($new_instance, $old_instance) {				
        return $new_instance;
    }

    /** @see WP_Widget::form */
    function form($instance) {				
      $title = esc_attr($instance['title']);
			$twitter_name = esc_attr($instance['twitter_name']);
			$amount = esc_attr($instance['twitts_amount']);
			$proflink = esc_attr($instance['twitter_proflink']);
			
        ?>
      <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'theme1591'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label></p>

      <p><label for="<?php echo $this->get_field_id('twitter_name'); ?>"><?php _e('Twitter Name:', 'theme1591'); ?> <input class="widefat" id="<?php echo $this->get_field_id('twitter_name'); ?>" name="<?php echo $this->get_field_name('twitter_name'); ?>" type="text" value="<?php echo $twitter_name; ?>" /></label></p>
      <p><label for="<?php echo $this->get_field_id('twitts_amount'); ?>"><?php _e('Twitts number:', 'theme1591'); ?> <input class="widefat" id="<?php echo $this->get_field_id('twitts_amount'); ?>" name="<?php echo $this->get_field_name('twitts_amount'); ?>" type="text" value="<?php echo $amount; ?>" /></label></p>	
			
        <?php 
    }

} // class  Widget
?>

Open in new window


See anything that needs correction?
Avatar of Ess Kay
Ess Kay
Flag of United States of America image

i have the same problem, its something with threir api
Twitter did, in fact, update their API last month.  You will want to use OAuth.  Time to refactor!  Some links to help:
https://twitter.com/twitterapi
https://dev.twitter.com/docs/twitter-libraries
Avatar of epichero22

ASKER

The widget doesn't use your Twitter password.  It simply takes the feed and displays it in the list.
Unfortunately they have dropped support for that version of the API, we now have to jump through more hoops, your code will not work anymore.
SOLUTION
Avatar of ScorchD
ScorchD
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Thanks for your input, I ended up using the steps listed in your link.