我可以問我如何在我的網站上顯示我的推文?就像Twitter的飼料thingie。我想要一張桌子,裏面只會顯示我的Twitter帳戶的推文。多謝你們!Twitter網站的推送
-6
A
回答
1
$xml = simplexml_load_file('http://twitter.com/statuses/user_timeline/{yourfeed}.rss');
// display each tweet
foreach ($xml->channel->item as $tweet)
{
echo $tweet->title . '<br />';
}
噸的其他解決方案,可以通過簡單的谷歌搜索找到。
入住這
1
Twitter提供一個JavaScript小部件,您可以複製並插入到你的網站。這是你在找什麼http://twitter.com/about/resources/widgets/widget_profile?
0
帖子這個PHP HTML的頭頂:
<?php
//Replace XXXXX with your twitter username
$twitterUsername = "XXXXX";
//Change number to amount of tweets you would like to display
$amountToShow = 5;
$twitterRssFeedUrl = 'https://api.twitter.com/1/statuses/user_timeline.rss?screen_name='.$twitterUsername.'&count='.$amountToShow;
$twitterPosts = false;
$xml = @simplexml_load_file($twitterRssFeedUrl);
if(is_object($xml)){
foreach($xml->channel->item as $twit){
if(is_array($twitterPosts) && count($twitterPosts)==$amountToShow){
break;
}
$d['title'] = stripslashes(htmlentities($twit->title,ENT_QUOTES,'UTF-8'));
$description = stripslashes(htmlentities($twit->description,ENT_QUOTES,'UTF-8'));
if(strtolower(substr($description,0,strlen($twitterUsername))) == strtolower($twitterUsername)){
$description = substr($description,strlen($twitterUsername)+1);
}
$d['description'] = $description;
$d['pubdate'] = strtotime($twit->pubDate);
$d['guid'] = stripslashes(htmlentities($twit->guid,ENT_QUOTES,'UTF-8'));
$d['link'] = stripslashes(htmlentities($twit->link,ENT_QUOTES,'UTF-8'));
$twitterPosts[]=$d;
}
}else{
die('Can`t fetch the feed you requested');
}
?>
帖子這在HTML的身體:
<ul>
<?php
if(is_array($twitterPosts)){
echo '';
foreach($twitterPosts as $post){
$data = $post['description'];
echo '<li>'.$data.'. ';
echo '<a href="'.$post['link'].'" class="timestamp">Posted '.date('F j, Y, g:i a',$post['pubdate']).'</a></li>';
}
echo '';
}else{
echo 'No Twitter posts have been made';//Error message
}
?>
</ul>
0
一對夫婦更多的功能,你可以添加的相對時間(即「昨天」「2周前」等),並將網址和用戶名轉換爲鏈接。
插入下面的代碼到你的PHP文件的頂部:
<?php
######################################
## DISPLAY TWITTER FEED
######################################
//Replace XXXXX with your twitter username
$twitterUsername = "XXXXX";
//Change number to amount of tweets you would like to display
$amountToShow = 5;
$twitterRssFeedUrl = 'https://api.twitter.com/1/statuses/user_timeline.rss?screen_name='.$twitterUsername.'&count='.$amountToShow;
$twitterPosts = false;
$xml = @simplexml_load_file($twitterRssFeedUrl);
if(is_object($xml)){
foreach($xml->channel->item as $twit){
if(is_array($twitterPosts) && count($twitterPosts)==$amountToShow){
break;
}
$d['title'] = stripslashes(htmlentities($twit->title,ENT_QUOTES,'UTF-8'));
$description = stripslashes(htmlentities($twit->description,ENT_QUOTES,'UTF-8'));
if(strtolower(substr($description,0,strlen($twitterUsername))) == strtolower($twitterUsername)){
$description = substr($description,strlen($twitterUsername)+1);
}
$d['description'] = $description;
$d['pubdate'] = strtotime($twit->pubDate);
$d['guid'] = stripslashes(htmlentities($twit->guid,ENT_QUOTES,'UTF-8'));
$d['link'] = stripslashes(htmlentities($twit->link,ENT_QUOTES,'UTF-8'));
$twitterPosts[]=$d;
}
}else{
die('Can`t fetch the feed you requested');
}
######################################
## REPLACE URLS AND USERS WITH LINKS
######################################
function hyperlinks($text) {
// Props to Allen Shaw & webmancers.com
// match protocol://address/path/file.extension?some=variable&another=asf%
//$text = preg_replace("/\b([a-zA-Z]+:\/\/[a-z][a-z0-9\_\.\-]*[a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%]*)\b/i","<a href=\"$1\" class=\"twitter-link\">$1</a>", $text);
$text = preg_replace('/\b([a-zA-Z]+:\/\/[\w_.\-]+\.[a-zA-Z]{2,6}[\/\w\-~.?=&%#+$*!]*)\b/i',"<a href=\"$1\" class=\"twitter-link\">$1</a>", $text);
// match www.something.domain/path/file.extension?some=variable&another=asf%
//$text = preg_replace("/\b(www\.[a-z][a-z0-9\_\.\-]*[a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%]*)\b/i","<a href=\"http://$1\" class=\"twitter-link\">$1</a>", $text);
$text = preg_replace('/\b(?<!:\/\/)(www\.[\w_.\-]+\.[a-zA-Z]{2,6}[\/\w\-~.?=&%#+$*!]*)\b/i',"<a href=\"http://$1\" class=\"twitter-link\">$1</a>", $text);
// match [email protected]
$text = preg_replace("/\b([a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]*\@[a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]{2,6})\b/i","<a href=\"mailto://$1\" class=\"twitter-link\">$1</a>", $text);
//mach #trendingtopics. Props to Michael Voigt
$text = preg_replace('/([\.|\,|\:|\¡|\¿|\>|\{|\(]?)#{1}(\w*)([\.|\,|\:|\!|\?|\>|\}|\)]?)\s/i', "$1<a href=\"http://twitter.com/#search?q=$2\" class=\"twitter-link\">#$2</a>$3 ", $text);
return $text;
}
function twitter_users($text) {
$text = preg_replace('/([\.|\,|\:|\¡|\¿|\>|\{|\(]?)@{1}(\w*)([\.|\,|\:|\!|\?|\>|\}|\)]?)\s/i', "$1<a href=\"http://twitter.com/$2\" class=\"twitter-user\">@$2</a>$3 ", $text);
return $text;
}
######################################
## DISPLAY RELATIVE DATES
######################################
//props to Osman Üngür for this (http://goo.gl/FrEMp)
function time2str($ts)
{
if(!ctype_digit($ts))
$ts = strtotime($ts);
$diff = time() - $ts;
if($diff == 0)
return 'now';
elseif($diff > 0)
{
$day_diff = floor($diff/86400);
if($day_diff == 0)
{
if($diff < 60) return 'just now';
if($diff < 120) return '1 minute ago';
if($diff < 3600) return floor($diff/60) . ' minutes ago';
if($diff < 7200) return '1 hour ago';
if($diff < 86400) return floor($diff/3600) . ' hours ago';
}
if($day_diff == 1) return 'Yesterday';
if($day_diff < 7) return $day_diff . ' days ago';
if($day_diff == 7) return '1 week ago';
if($day_diff < 31) return ceil($day_diff/7) . ' weeks ago';
if($day_diff < 60) return 'last month';
return date('F Y', $ts);
}
else
{
$diff = abs($diff);
$day_diff = floor($diff/86400);
if($day_diff == 0)
{
if($diff < 120) return 'in a minute';
if($diff < 3600) return 'in ' . floor($diff/60) . ' minutes';
if($diff < 7200) return 'in an hour';
if($diff < 86400) return 'in ' . floor($diff/3600) . ' hours';
}
if($day_diff == 1) return 'Tomorrow';
if($day_diff < 4) return date('l', $ts);
if($day_diff < 7 + (7 - date('w'))) return 'next week';
if(ceil($day_diff/7) < 4) return 'in ' . ceil($day_diff/7) . ' weeks';
if(date('n', $ts) == date('n') + 1) return 'next month';
return date('F Y', $ts);
}
}
?>
然後張貼下面的代碼在HTML的身體:
<ul>
<?php
if(is_array($twitterPosts)){
echo '';
foreach($twitterPosts as $post){
$data = hyperlinks($post['description']);
$data = twitter_users($data);
echo '<li>'.$data.'. ';
echo '<a href="'.$post['link'].'" class="timestamp">Posted '.time2str(date($post['pubdate'])).'</a></li>';
}
echo '';
}else{
echo 'No Twitter posts have been made';//Error message
}
?>
</ul>
相關問題
- 1. 網站推送通知
- 2. OneSignal網站推送流程
- 3. GitHub推送到Azure網站
- 4. 數據推送到網站
- 5. 通過webview的網站推送通知?
- 6. 基於PHP的網站推送通知
- 7. 網站的Twitter流
- 8. Twitter網站流
- 9. IDE,SVN和推送到網站!
- 10. 上傳/推送數據到網站
- 11. 將facebook圖片推送到ASP.net網站?
- 12. 將內容推送到像facebook,twitter linkedin,youtube和vimeo等社交網站
- 13. Twitter的網站如何計算推文發佈的時間?
- 14. 推廣網站
- 15. 自定義推特來自我的Twitter使用Ruby On Rails Twitter推送twitter plm
- 16. 將twitter上的最新推文嵌入到網站上
- 17. 如何在我的網站上添加twitter推文功能?
- 18. 在我的網站上整合Twitter推文
- 19. 從我的網站發送推送通知到pushwoosh服務器
- 20. 發送來自Go Appengine網站的Apple推送通知
- 21. Twitter推送組件的CSS覆蓋
- 22. Joomla 2.5.6擴展從joomla網站發佈推文到twitter牆
- 23. 從推薦網站
- 24. 通過網站發送解析推送通知
- 25. 每次更新網站時都會發送推送通知
- 26. 如何從網站聊天發送android推送通知
- 27. Omniatuh設計的Twitter不發送用戶返回到網站
- 28. Twitter離線網站概念
- 29. Twitter oAuth爲客戶網站
- 30. twitter在drupal 7網站
看這個問題的http://計算器.COM /問題/ 422879 /最佳Twitter的PHP庫 –