zer0ruth
zer0ruth

Reputation: 89

Show Twitter Feed on my website

Up until a few weeks ago the below code worked great to grab my last three tweets and display them on my website. now it's not working. I've looked through Twitter's messages boards to see if something changed to no avail.

Does anyone know how to effectively display your latest tweets on a website using php?

my original code is here. Like I said, this worked up until a few weeks ago:

$twitterUsername = "myUsername";
$amountToShow = 3;
$twitterRssFeedUrl = 'https://api.twitter.com/1/statuses/user_timeline.rss?screen_name='.$twitterUsername.'&count='.$amountToShow;

$twitterPosts = false;
$xml = @simplexml_load_file($twitterRssFeedUrl);
if(is_object($xml)){
    foreach($xml->channel->item as $twit){
    if(is_array($twitterPosts) && count($twitterPosts)==$amountToShow){
    break;
}
$d['title'] = stripslashes(htmlentities($twit->title,ENT_QUOTES,'UTF-8'));
$description = stripslashes(htmlentities($twit->description,ENT_QUOTES,'UTF-8'));
if(strtolower(substr($description,0,strlen($twitterUsername))) == strtolower($twitterUsername)){
    $description = substr($description,strlen($twitterUsername)+1);
}
$d['description'] = $description;
$d['pubdate'] = strtotime($twit->pubDate);
$d['guid'] = stripslashes(htmlentities($twit->guid,ENT_QUOTES,'UTF-8'));
$d['link'] = stripslashes(htmlentities($twit->link,ENT_QUOTES,'UTF-8'));
$twitterPosts[]=$d;
}
}else{

die('Can`t fetch the feed you requested');
}

and then it turns up in the html like so:

 <dl class="twitter">
      <dt>Twitter Feed</dt>
<?php
if(is_array($twitterPosts)){
echo '';
foreach($twitterPosts as $post){ 
$data = hyperlinks($post['description']);
$data = twitter_users($data);
 echo '<dd>'.$data.'. ';
 echo '<a href="'.$post['link'].'" class="timestamp">Posted '.time2str(date($post['pubdate'])).'</a></dd>';
}
echo '';
}else{
    echo 'No Twitter posts have been made';//Error message
}
?>
     <dd>

Upvotes: 0

Views: 8229

Answers (2)

Tim
Tim

Reputation: 8606

Twitter API 1.0 that you're using has been switched off, as of a few weeks ago.

Read up on the API 1.1 here: https://dev.twitter.com/docs/api

There are tonnes of PHP libraries for working with the new API, including mine.

Upvotes: 2

Rob W
Rob W

Reputation: 9142

The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.

Upvotes: 0

Related Questions