<?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;
}
?>
插件56:发送Tweet
最新推荐文章于 2023-10-29 15:12:29 发布