插件56:发送Tweet

<?php // Plug-in 56: Send Tweet
/*
 * 插件说明:
 * 插件接受一个Twitter用户名、口令和一个需要发送的信息,然后把这个消息发送到这个用户的账户里。若发送成功,则返回TRUE,否则,返回FALSE。
 * 它需要以下参数:
 * $user Twitter用户名。
 * $pass $user用户的口令。
 * $text 是最长140字符的消息。
 */
// 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';
$text   = 'Check out the book Plug-in PHP!';
$result = PIPHP_SendTweet($user, $pass, $text);

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

function PIPHP_SendTweet($user, $pass, $text)
{
   // Plug-in 56: Send Tweet
   //
   // This plug-in sends a tweet to a Twitter account. The
   // arguments required are:
   //
   //    $user: Twitter username
   //    $pass: Twitter password
   //    $text: Text to Tweet
   //
   // Upon success this plug-in returns the XML text
   // returned by the called web page, otherwise it will
   // return FALSE.

   $text = substr($text, 0, 140);
   $url  = 'http://twitter.com/statuses/update.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, "status=$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、付费专栏及课程。

余额充值