-
-
Save wkw/5776067 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
/* enter your Twitter username here */ | |
DEFINE('TWITTER_USERNAME', 'replace-me'); | |
/* | |
/* this is where you put in all of your secret spices */ | |
/* check out this guide for an explaination: http://stackoverflow.com/questions/12916539/simplest-php-example-retrieving-user-timeline-with-twitter-api-version-1-1/15314662#15314662 */ | |
$settings = array( | |
'oauth_access_token' => "", | |
'oauth_access_token_secret' => "", | |
'consumer_key' => "", | |
'consumer_secret' => "" | |
); | |
/* | |
/* Include Twitter-API-PHP: http://github.com/j7mbo/twitter-api-php */ | |
include('TwitterAPIExchange.php'); | |
$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json'; | |
$getfield = '?screen_name='. TWITTER_USERNAME; | |
$requestMethod = 'GET'; | |
$twitter = new TwitterAPIExchange($settings); | |
$result = $twitter->setGetfield($getfield) | |
->buildOauth($url, $requestMethod) | |
->performRequest(); | |
/* | |
/* get a nice object we can work with */ | |
$jsonDecoded = json_decode($result); | |
/* | |
/* generate the XML */ | |
header("Content-Type: application/rss+xml"); | |
$dom = new DomDocument("1.0", "ISO-8859-1"); | |
$dom->version = "1.0"; | |
$dom->encoding = "ISO-8859-1"; | |
$rssElem = $dom->createElement('rss'); | |
$channelElem = $rssElem->appendChild( $dom->createElement('channel') ); | |
foreach($jsonDecoded as $item) | |
{ | |
$itemElem = $channelElem->appendChild ( $dom->createElement('item') ); | |
$itemElem->appendChild ( $dom->createElement('title', $item->text) ); | |
$itemElem->appendChild ( $dom->createElement('link', 'https://twitter.com/'. TWITTER_USERNAME .'/status/'. $item->id_str ) ); | |
//$itemElem->appendChild ( $dom->createElement('description', $item->text) ); // not usually needed for Twitter RSS | |
} | |
echo $dom->saveXML($rssElem); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment