LOADING STUFF...

PHP封装的Twitter访问类实例

技术教程2小时前更新 北陌
13 0 0

PHP封装的Twitter访问类实例

本文实例讲述了PHP封装的Twitter访问类。分享给大家供大家参考。具体如下:

class Twitter {
/**
* Method to make twitter api call for the users timeline in XML
*
* @access private
* @param $twitter_id, $num_of_tweets
* @return $xml
*/
private function api_call($twitter_id, $num_of_tweets) {
$c = curl_init();
curl_setopt($c, CURLOPT_URL, “http://twitter.com/statuses/user_timeline/$twitter_id.xml?count=$num_of_tweets”);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($c, CURLOPT_TIMEOUT, 5);
$response = curl_exec($c);
$response_info = curl_getinfo($c);
curl_close($c);
if (intval($response_info[http_code]) == 200) {
$xml = new SimpleXMLElement($response);
return $xml;
} else {
return false;
}
}
/**
* Method to add hyperlink html tags to any urls, twitter ids or hashtags in tweet
*
* @access private
* @param $text
* @return $text
*/
private function process_links($text) {
$text = utf8_decode($text);
$text = preg_replace(@(https?://([-w.] ) (d )?(/([w/_.]*(?S )?)?)?)@,

© 版权声明

相关文章

暂无评论

暂无评论...