色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

PHP調(diào)用Twitter的RSS的實(shí)現(xiàn)代碼

雜感
這個(gè)欄目最開始調(diào)用微博飯否的API來做的,因?yàn)楸娝苤木壒剩埛駸o法使用了,后來采用騰訊的滔滔API來實(shí)現(xiàn).2010年1月26日滔滔業(yè)務(wù)將會(huì)開始和QQ空間心情整合,只能考慮放棄。思來想去,最終還是考慮用Twitter來實(shí)現(xiàn),不過Twitter在國內(nèi)無法訪問,不能采用js的方式來調(diào)用。本博客的服務(wù)器才國外,用php的方式訪問Twitter的API應(yīng)該沒有問題,雖然有現(xiàn)成的wordpress插件“Twitter Tools”可以用,但本著盡量少用插件的目的,決定直接用php在wordpress主題里實(shí)現(xiàn)。twritter提供的API接口很豐富,研究一下覺得調(diào)用Twitter RSS的API比較簡單,實(shí)現(xiàn)如下功能:

1、抓取twitter RSS的內(nèi)容,不需要密碼,只需要用戶名。
2、格式化RSS的內(nèi)容,顯示用戶本人的推的內(nèi)容及時(shí)間,排除 @replies 回復(fù)給他人的信息內(nèi)容。

代碼如下:
復(fù)制代碼 代碼如下:
<!-- my tritter -->
<?php
$username='xjb';//change this to your twitter username修改為你的twitter 用戶名
$feedURL='http://twitter.com/statuses/user_timeline/'.$username.'.rss';
$excludePattern='/'.$username.': @/'; //excludes any @replies排除@replies 內(nèi)容
$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 in China --轉(zhuǎn)成中國時(shí)區(qū)
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 target="_blank">更多...</a></div>
<!-- my tritter -->

源代碼
復(fù)制代碼 代碼如下:
<!-- my tritter -->
<?php

$username='xjb'; //change this to your twitter username --修改為你的twitter 用戶名
$feedURL='http://twitter.com/statuses/user_timeline/'.$username.'.rss';
$excludePattern='/'.$username.': @/'; //excludes any @replies --排除 @replies 內(nèi)容
$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 in China --轉(zhuǎn)成中國時(shí)區(qū)
$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 target="_blank">更多...</a></div>
<!-- my tritter -->

php技術(shù)PHP調(diào)用Twitter的RSS的實(shí)現(xiàn)代碼,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 中西区| 察雅县| 甘孜| 龙泉市| 札达县| 杂多县| 莎车县| 禄丰县| 中宁县| 拉萨市| 万载县| 福贡县| 高要市| 北川| 丘北县| 土默特左旗| 广饶县| 东源县| 营口市| 济阳县| 凤阳县| 德阳市| 涪陵区| 惠安县| 城口县| 南川市| 上蔡县| 本溪市| 敦煌市| 丹棱县| 正阳县| 德令哈市| 合作市| 长泰县| 镇安县| 武安市| 万荣县| 临汾市| 孝义市| 阳泉市| 嘉义市|