Index: twitter.inc =================================================================== --- twitter.inc (revision 4) +++ twitter.inc (working copy) @@ -141,7 +141,36 @@ return drupal_http_request($url, $headers, 'POST', $data); } + /** + * Send a direct message to another Twitter user. + * + * @param $screen_name + * The screen name of a Twitter.com user. + * @param $password + * The password of a Twitter.com user. + * @param $to + * The ID or screen name of the recipient user. + * @param $text + * The text to post. Strings longer than 140 characters will be truncated by + * Twitter. + * @return + * The full results of the Drupal HTTP request, including the HTTP response + * code returned by Twitter.com. + */ +function twitter_send_dm($screen_name, $password, $to, $text) { + $url = "http://" . variable_get('twitter_api_url', 'twitter.com') . "/direct_messages/new.xml"; + + $headers = array('Authorization' => 'Basic '. base64_encode($screen_name .':'. $password), + 'Content-type' => 'application/x-www-form-urlencoded'); + $data = 'text='. urlencode($text); + $data .= '&user='.$to; + + return drupal_http_request($url, $headers, 'POST', $data); +} + + +/** * Fetch the full information for a Twitter.com account. * * This function requires an authenticated connection for the account in