Fatal error: Call to undefined method WP_Error::get_item_quantity()

I would say you are probably receiving a WP_Error on first run.

around the $maxitems and $rss_items lines, add:

if( ! is_wp_error( $rss ) ) {
    $maxitems = $rss->get_item_quantity(3);
    $rss_items = $rss->get_items(0, $maxitems);
}

As seen in the example.

tech