Twitter API – Creating lists with PHP and cURL

This post was written by Brandon on December 1, 2009
Posted Under: PHP

I needed to be able to create Twitter lists for my Tweet Large project. So, here is a method i made to do this. It is in PHP and requires the cURL library. Simply pass the new list name, as well as the username and password and the list will be created.

 
public function createList($listname='', $username='', $password=''){
if (!empty($listname) && !empty($username) && !empty($password)){
$url = 'http://api.twitter.com/1/'.$username.'/lists.xml';
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "name=$listname");
curl_setopt($curl_handle, CURLOPT_USERPWD, $username.":".$password);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
   }
}
 

Add a Comment

required, use real name
required, will not be published
optional, your blog address