views:

34

answers:

0

I'm trying to add a user (by variable $id) to a Twitter List using PHP CURL, and I can't get it to work.

$curl_handle = curl_init();

curl_setopt($curl_handle, CURLOPT_URL, "http://twitter.com/username/list/members.xml");

curl_setopt($curl_handle, CURLOPT_POST, 1);

curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "id=$id");

curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);

curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl_handle, CURLOPT_USERPWD, "username:password");

curl_setopt($curl_handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

curl_setopt($curl_handle, CURLOPT_VERBOSE, 1);

$result = curl_exec($curl_handle);

// Look at the returned header

$resultArray = curl_getinfo($curl_handle);

curl_close($curl_handle);

if($resultArray['http_code'] == "200"){

   echo 'Success';

} else {

   echo var_dump($resultArray);

}

The var_dump reveals that the http_code of the return is 403.

Var_dump:

array(20) { ["url"]=> string(44) "http://twitter.com/user/userlist/members.xml" ["content_type"]=> string(30) "application/xml; charset=utf-8" ["http_code"]=> int(403) ["header_size"]=> int(940) ["request_size"]=> int(206) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(0.222188) ["namelookup_time"]=> float(0.000538) ["connect_time"]=> float(0.079296) ["pretransfer_time"]=> float(0.079378) ["size_upload"]=> float(0) ["size_download"]=> float(146) ["speed_download"]=> float(657) ["speed_upload"]=> float(0) ["download_content_length"]=> float(146) ["upload_content_length"]=> float(0) ["starttransfer_time"]=> float(0.22209) ["redirect_time"]=> float(0) }

The username, password and the xml file are all properly set, with 100% confidence.