Created
May 7, 2009 16:00
-
-
Save ironsjp/108180 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 | |
class TwitterAPI { | |
private $_curl_handle; | |
private $_curl_info; | |
private $_curl_errno; | |
private $_curl_errmsg; | |
private $_curl_options = array( | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_HEADER => false, | |
CURLOPT_FOLLOWLOCATION => true, | |
CURLOPT_ENCODING => '', | |
CURLOPT_USERAGENT => 'tfs', | |
CURLOPT_AUTOREFERER => true, | |
CURLOPT_CONNECTTIMEOUT => 60, | |
CURLOPT_TIMEOUT => 60, | |
CURLOPT_MAXREDIRS => 10, | |
CURLOPT_VERBOSE => 1, | |
); | |
function __construct() { | |
$this->_curl_handle = curl_init(); | |
curl_setopt_array($this->_curl_handle, $this->_curl_options); | |
} | |
function close() { | |
curl_close($this->_curl_handle); | |
return; | |
} | |
function getFriends($user_id) { | |
$url = 'http://twitter.com/friends/ids.json?user_id=' . $user_id; | |
curl_setopt($this->_curl_handle, CURLOPT_URL, $url); | |
$json = curl_exec($this->_curl_handle); | |
$this->_curl_errno = curl_errno($this->_curl_handle); | |
$this->_curl_errmsg = curl_error($this->_curl_handle); | |
$this->_curl_info = curl_getinfo($this->_curl_handle); | |
return json_decode($json, true); | |
} | |
function getCurlErrNo() { | |
return $this->_curl_errno; | |
} | |
function getCurlErrMsg() { | |
return $this->_curl_errmsg; | |
} | |
function getCurlInfo() { | |
return $this->_curl_info; | |
} | |
} | |
$twitter = new TwitterAPI(); | |
$friends = $twitter->getFriends(8831502); | |
print_r($friends); | |
$twitter->close(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment