1

I'm trying to get some of the latest posts from a Twitter account, without a plugin. According to Botcrawl.com's tutorial, this should be enough:

<ul>
<?php
include_once(ABSPATH . WPINC . '/feed.php');
$rss = fetch_feed('https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=BarackObama');
$maxitems = $rss->get_item_quantity(4);
$rss_items = $rss->get_items(0, $maxitems);
?>

<ul>
<?php if ($maxitems == 0) echo '<li>No items.</li>';
else
// Loop through each feed item and display each item as a hyperlink.
foreach ( $rss_items as $item ) : ?>
<li>
<a href='<?php echo $item->get_permalink(); ?>'>
<?php echo $item->get_title(); ?>
</a>
</li>
<?php endforeach; ?>
</ul>

However, I get the following error:

Fatal error: Call to undefined method WP_Error::get_item_quantity() in /Users/username/Desktop/journal_wp/wp-content/themes/Journal_theme/index.php on line 155

Has anyone had any experience with this, and know why it is calling a fatal error?

1 Answer 1

1

That tutorial is no longer valid as Twitter's API have changed June 2013. There are are some great tutorials that came out just after June 2013 for Twitter API v1.1. Why not use a plugin. It is actually better to go that root as these plugin developers keep their plugins up to date and are quick to modify them if someone like twitter change their API

2
  • Thankyou, I may do that. Is there any you recommend (if I need to be able to customize the CSS)
    – tmyie
    Commented Feb 26, 2014 at 13:02
  • That is all personal choice. Go and try a few. Best of luck Commented Feb 26, 2014 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.