Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('../../Muskie/codebird.php');
- require_once('../../Muskie/myInfo.php');
- header('Content-type:text/xml; charset=utf-8'); // You have to do this early to have a valid RSS feed
- Codebird::setConsumerKey(myInfo::MY_TWITTER_PUBLIC_KEY, myInfo::MY_TWITTER_PRIVATE_KEY);
- $cb = Codebird::getInstance();
- $cb->setToken(myInfo::MY_TWITTER_ACCESS_TOKEN, myInfo::MY_TWITTER_ACCESS_TOKEN_SECRET);
- $searchResults = null;
- $searchTerm = null;
- if(isset($_GET["q"]))
- {
- $searchTerm = $_GET["q"]; // This should already be URL encoded I imagine, will have to test works for Vancouver
- $encodedQuery = urlencode( $searchTerm ); // Re-encoded just in case
- $params = array(
- 'q' => $encodedQuery,
- 'lang' => 'en',
- 'result_type' => 'recent'
- );
- $searchResults = $cb->search_tweets($params);
- }
- // Begin the RSS Feed
- echo '<?xml version="1.0" encoding="UTF-8" ?>';
- ?>
- <rss version="0.91"> <!-- not sure if I should bother with RSS 2.0, simple is best IMHO -->
- <channel>
- <?php echo('<title>Twitter Search Result Feed for ' . $searchTerm . ' </title>'); ?>
- <link>http://www.muschamp.ca</link>
- <description>
- Recent tweets for keyword search as an RSS feed.
- </description>
- <language>en-us</language>
- <pubDate><?php echo date("D, d M Y H:i:s T"); ?></pubDate>
- <?php
- foreach($searchResults->statuses as $this_tweet)
- {
- print('<item>' . "\n");
- print('<title>' . htmlspecialchars($this_tweet->text, 16, "UTF-8") . '</title>'. "\n");
- print('<link>http://twitter.com/' . $this_tweet->user->screen_name . '/status/' . $this_tweet->id_str . '</link>' . "\n");
- print('<description>' . $this_tweet->text . '</description>'. "\n");
- $pubTime = strtotime($this_tweet->created_at);
- $pubDate = date("D, d M Y H:i:s T", $pubTime);
- print('<pubDate>' . $pubDate . '</pubDate>' . "\n");
- print('</item>'. "\n");
- }
- ?>
- </channel>
- </rss>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement