You are here

function twitter_send_dm in Twitter 6.2

Send a direct message to another Twitter user.

Parameters

$screen_name: The screen name of a Twitter.com user.

$password: The password of a Twitter.com user.

$to: The ID or screen name of the recipient user.

$text: The text to post. Strings longer than 140 characters will be truncated by Twitter.

Return value

The full results of the Drupal HTTP request, including the HTTP response code returned by Twitter.com.

File

./twitter.inc, line 159
A wrapper API for the Twitter microblogging service.

Code

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);
}