Sunday, July 25, 2010

Problems deleting Direct Messages from twitter using PHP/Curl and the Supertweet.net api

Basically my problem is outlined above. I am trying to delete direct messages using the message id - using php and the supertweet.api - I've looked at the twitter API wiki have not found what I am doing wrong.

This is the response I get back:

The method specified in the request is not allowed for the resource identified by the request URI You can get technical details http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.6

Going to the w3.org web site this is what it says:

10.4.6 405 Method Not Allowed

The method specified in the Request-Line is not allowed for the resource identified by the Request-URI. The response MUST include an Allow header containing a list of valid methods for the requested resource.

Which to me isn't helpful.

My code is this:

$msgdestroy = "http://api.supertweet.net/1/direct_messages/destroy/";
$msgidid = $checksum3[$counter1] . '.xml'; //this is the id of the message.

function distroydm($destroyurl,$user,$password, $msgidid) {
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$destroyurl");
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, "$msgidid");
curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$user:$password");
$buffer=curl_exec($curl_handle);
curl_close($curl_handle);

return $buffer;
}

The twitter API says, to do this:
curl -u user:password --http-request DELETE http://api.twitter.com/1/direct_messages/destroy/88619848.xml

Which would be a command line, of the above code (I think), when I run it via the command line, however - I get the same error directing me back to w3.org

I've googled this, and didn't find anything helpful - Hoping someone who understands the API a bit better maybe able to give me some idea as to what I am doing wrong.

-Thanks - LeRoy, KD8BXP