config = array_merge(
array(
// change the values below to ones for your application
'consumer_key' => '[your consumer key]',
'consumer_secret' => '[your consumer secret]',
'token' => '[your access token]',
'secret' => '[your access secret]',
//'bearer' => 'YOUR_OAUTH2_TOKEN',
'user_agent' => 'TweetPull4RSS ' . self::VERSION . ' with tmhOAuth ' . parent::VERSION . ' - //github.com/themattharris/tmhOAuth',
),
$config
);
parent::__construct($this->config);
}
public function openOutputFile() {
$this->file = '/full/path/to/result/rss/file/' . $this->twitter_userid . '.xml';
}
public function writeHeader() {
$output = '' . "\n";
$output .= '' . "\n";
$output .= "\t\t" . '' . $this->twitter_name . ' (' . $this->twitter_userid . ') on Twitter' . "\n";
$output .= "\t\t" . 'https://twitter.com/' . $this->twitter_userid . '' . "\n";
$output .= "\t\t" . '' . $this->twitter_desc . '' . "\n";
$output .= "\t\t" . 'en-US' . "\n";
$output .= "\t\t" . '' . "\n";
$output .= "\t\t" . ' ' . $this->twitter_name . ' (' . $this->twitter_userid . ') on Twitter' . "\n";
$output .= "\t\t" . ' ' . $this->twitter_icon . '' . "\n";
$output .= "\t\t" . ' https://twitter.com/' . $this->twitter_userid . '' . "\n";
$output .= "\t\t" . '' . "\n";
file_put_contents($this->file, $output);
}
public function writeFooter() {
$output = "\t" . '' . "\n";
$output .= "";
$current = file_get_contents($this->file);
$current .= $output;
file_put_contents($this->file, $current);
}
public function Truncate($string, $length, $stopanywhere=false) {
//truncates a string to a certain char length, stopping on a word if not specified otherwise.
if (strlen($string) > $length) {
//limit hit!
$string = substr($string,0,($length -3));
if ($stopanywhere) {
//stop anywhere
$string .= '...';
} else{
//stop on a word.
$string = substr($string,0,strrpos($string,' ')).'...';
}
}
return $string;
}
}
$tmhOAuth = new tmhOAuthExample();
$code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/statuses/user_timeline'), array('screen_name' => $passedID));
$decoded = json_decode($tmhOAuth->response['response'], true);
if (isset($decoded[0]["created_at"])) {
$tmhOAuth->twitter_userid = $decoded[0]["user"]["screen_name"];
$tmhOAuth->twitter_name = $decoded[0]["user"]["name"];
$tmhOAuth->twitter_desc = $decoded[0]["user"]["description"];
$tmhOAuth->twitter_icon = $decoded[0]["user"]["profile_image_url"];
$tmhOAuth->openOutputFile();
$tmhOAuth->writeHeader();
foreach ($decoded as $i) {
$p = explode(" ", $i["created_at"]);
$dateFinal = $p[0] . ', ' . $p[2] . ' ' . $p[1] . ' ' . $p[5] . ' ' . $p[3] . ' ' . $p[4];
$content = "\t\t" . '- ' . "\n";
// $content .= "\t\t" . ' ' . $tmhOAuth->Truncate($i["text"], 50) . '' . "\n";
$content .= "\t\t" . ' ' . $i["text"] . '' . "\n";
$content .= "\t\t" . ' https://twitter.com/' . $tmhOAuth->twitter_userid . '/status/' . $i["id_str"] . '' . "\n";
$content .= "\t\t" . ' https://twitter.com/' . $tmhOAuth->twitter_userid . '/status/' . $i["id_str"] . '' . "\n";
$content .= "\t\t" . ' ' . "\n";
$content .= "\t\t" . ' ' . $tmhOAuth->twitter_userid . '' . "\n";
$content .= "\t\t" . ' ' . $dateFinal . '' . "\n";
$content .= "\t\t" . '
' . "\n";
$current = file_get_contents($tmhOAuth->file);
$current .= $content;
file_put_contents($tmhOAuth->file, $current);
}
$tmhOAuth->writeFooter();
} elseif (isset($decoded[0]["errors"])) {
echo "Error: " . $decoded[0]["errors"][0]["message"] . "\n\n";
}
?>