插件57:直接发送tweet消息

<?php // Plug-in 57: Send Direct Tweet
/*
 * 插件说明:
 * 插件接受一个Twitter账户的用户名、口令、接收者的姓名和发送内容。然后把这个消息发送给这个接收者的账户。
 * 如发送成功,返回TRUE,否则返回FALSE。
 * 它需要以下参数:
 * $user Tiwtter用户名。
 * $pass $user用户的口令。
 * $to Tweet消息直接接收者的用户名。
 * $text 最多140字的Tweet消息。
 */
// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link

$user   = 'twitteruser';
$pass   = 'twitterpass';
$to     = 'otheruser';
$text   = 'A test message from twitteruser to otheruser';
$result = PIPHP_SendDirectTweet($user, $pass, $to, $text);

if ($result) echo "Direct Tweet '$text' sent to '$to'.";
else echo 'Tweet failed';

function PIPHP_SendDirectTweet($user, $pass, $to, $text)
{
   // Plug-in 57: Send Direct Tweet
   //
   // This plug-in sends a Direct Message to a Twitter
   // account. The arguments required are:
   //
   //    $user: Twitter username
   //    $pass: Twitter password
   //    $to:   Recipient of Direct Tweet
   //    $text: Text to Tweet
   //
   // Upon success this plug-in returns TRUE, otherwise it
   // will return FALSE.

   $text = substr($text, 0, 140);
   $url  = 'http://twitter.com/direct_messages/new.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,
      "user=$to&text=$text");
   curl_setopt($curl_handle, CURLOPT_USERPWD, "$user:$pass");
   $result = curl_exec($curl_handle);
   curl_close($curl_handle);

   $xml = simplexml_load_string($result);
   if ($xml == FALSE) return FALSE;
   elseif ($xml->text == $text) return TRUE;
   else return FALSE;
}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值