Skip to content

Instantly share code, notes, and snippets.

@ironsjp
Created May 7, 2009 16:00
Show Gist options
  • Save ironsjp/108180 to your computer and use it in GitHub Desktop.
Save ironsjp/108180 to your computer and use it in GitHub Desktop.
<?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