[英]How to display tweets from twitter using Hash tags by PHP+MySQL
[英]how do i display twitter tweets from twitter using php
我想使用php在Twitter上的網頁中顯示Twitter推文。 有人有主意幫我
提前致謝。
您好,請看一下Twitter API: http : //dev.twitter.com/pages/libraries#php
除了Twitter開發人員頁面上列出的庫之外,您還可以使用Zend_Service_Twitter
與Twitter API一起使用:
Zend_Service_Twitter
提供»Twitter REST API的客戶端。Zend_Service_Twitter
允許您查詢公共時間軸。 如果您提供Twitter的用戶名和OAuth詳細信息,它將允許您獲取和更新狀態,回復朋友,直接發送消息的朋友,將推文標記為收藏,等等。
如果您想要一個真正簡單的解決方案,甚至可以使用twitter小部件: http : //twitter.com/goodies/widgets
您可以向Dabr學習,這是一個用PHP編寫的PHP前端。 它幾乎包含了Twitter API的所有功能。
這是我發現的最基本的功能。 它基於JavaScript,因此顯然您不會遇到每小時API調用限制的問題。 它為您提供了標記,您可以根據自己的喜好輕松地對其進行修改。
http://twitter.com/widgets/html_widget
哦,不用擔心所有的人都在批評您的問題。 我沒有在該站點的任何地方讀過指南,您所質疑的問題必須進行重大改進才能打動所有人。 ;-)
好的,所以我碰到了這篇文章,並為答案而苦苦掙扎...但這是我的解決方案...工作正常...我看到的唯一問題是基於獲取RSS提要,Twitter非常渴望獲得它擺脫-但是對於一個簡單的解決方案,它很有吸引力。
function twitter_status(){
$twitter_name = "YOUR_TWITTER_USERNAME";
$myFile = "http://api.twitter.com/1/statuses/user_timeline.rssscreen_name=".$twitter_name;
$dom = new DOMDocument();
$dom -> load($myFile);
$items = $dom->getElementsByTagName('item');
$max_items = 1; // Number of tweets to return.
$count = 0;
foreach ($items as $item) {
// Select all the elements in the XML document named "Description"
// The different elements available are Title, Description, pubDate, guid, link and twitter:source
// You can find this out by opening the link to your twitter rss feed
$tweets = $item->getElementsByTagName('description');
$tweet_string = $tweets->item(0)->nodeValue;
$tweet_string = substr($tweet_string,strpos($tweet_string,":")+2);
$tweet_date = $item->getElementsByTagName('pubDate');
$tweet_date = $tweet_date->item(0)->nodeValue;
$tweet_date = substr($tweet_date,0,16); // Get rid of the excess times at the end of the date
echo ("<li class='timestamp tweet_".$count."'>Posted ".$tweet_date."</li><li class='tweet tweet_".$count."'>".makelink($tweet_string)."</li>");
$count = $count+1;
if ($count>=$max_items){ break; }
}
}
function makeLink($string){
// Function to convert url to a link
/*** make sure there is an http:// on all URLs ***/
$string = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i", "$1http://$2",$string);
/*** make all URLs links ***/
$string = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<a target=\"_blank\" href=\"$1\">$1</A>",$string);
/*** make all emails hot links ***/
$string = preg_replace("/([\w-?&;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?))/i","<A HREF=\"mailto:$1\">$1</A>",$string);
return $string;
}
所以這是我的解決方案,但是它非常符合我的需求-但是你們中的大多數人都希望可以解決這個問題並進行必要的調整。 我不是一個特別出色的程序員,因此,如果我犯了公然的錯誤或可以改進此腳本,我將不勝感激。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.