This column began to call the micro-Bo Rice no API to do, because the well-known reason, the rice can not be used, and then use Tencent's surging API to achieve. January 26, 2010 surging business will start and QQ space mood integration, can only consider giving up. Reasoning, eventually consider using Twitter to achieve, but Twitter is not accessible in the country, can not use JS way to invoke. This blog server only abroad, the way to use PHP to access Twitter API should be no problem, although there are ready-made WordPress plug-ins "Twitter Tools" can be used, but in the spirit of minimizing the purpose of using Plug-ins, decided to use PHP directly in the theme of WordPress. Twritter provides a rich API interface, and studies the API that calls Twitter RSS is relatively simple, to achieve the following functions:
1, grab the content of Twitter RSS, do not need a password, only need user name.
2, format the content of RSS, display the user's push content and time, excluding @replies reply to others information content.
The code is as follows:
Copy Code code as follows:
<!--my Tritter-->
<?php
$username = ' XJB ';//change this to your Twitter username modified for your Twitter username
$feedURL = ' http://twitter.com/statuses/user_timeline/'. $username. RSS ';
$excludePattern = '/'. $username. ': @/'; Excludes any @replies excluding @replies content
$count =5;//Show Count
$i = 0;
if (! $xml =simplexml_load_file ($feedURL)) {
Trigger_error (' Error ', e_user_error);
}
foreach ($xml->channel->item as $item) {
if (! Preg_match ("$excludePattern", $item->title)) {
$filteredTitle =htmlspecialchars ("$item->title");
$filteredTitle =str_replace ("$username:", "", $filteredTitle);
Convert the time zone into China
Date_default_timezone_set (' Asia/shanghai ');
$i + +;
if ($i > $count)
{
Break
}
?>
<li><?php echo $filteredTitle;?>
(<?php echo Date ("Y-m-d h:i:s", Strtotime ($item->pubdate));?>) </li>
<?php}}?>
<div align= "Right" >
<a href= "HTTP://TWITTER.COM/XJB" target= "_blank" > more ...</a></div>
<!--my Tritter-->
Source
Copy Code code as follows:
<!--my Tritter-->
<?php
$username = ' XJB '; Change this to your Twitter username--Modify your Twitter username
$feedURL = ' http://twitter.com/statuses/user_timeline/'. $username. RSS ';
$excludePattern = '/'. $username. ': @/'; Excludes any @replies--excluding @replies content
$count =5;//Show Count
$i = 0;
if (! $xml =simplexml_load_file ($feedURL)) {
Trigger_error (' Error ', e_user_error);
}
foreach ($xml->channel->item as $item) {
if (! Preg_match ("$excludePattern", $item->title)) {
$filteredTitle =htmlspecialchars ("$item->title");
$filteredTitle =str_replace ("$username:", "", $filteredTitle);
Date_default_timezone_set (' Asia/shanghai '); Convert the time zone into China
$i + +;
if ($i > $count)
{
Break
}
?>
<li><?php echo $filteredTitle;?> (<?php echo Date ("Y-m-d h:i:s", Strtotime ($item->pubdate);?>) </li>
<?php}}?>
<div align= "right" ><a href= "HTTP://TWITTER.COM/XJB" target= "_blank" > more ...</a></div>
<!--my Tritter-->