<?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;
}
?>
插件57:直接发送tweet消息
最新推荐文章于 2018-10-09 11:36:49 发布