我需要显示最后的推文在网页上,并希望控制样式的推文从CSS。即使禁用了Javascript,也应该看到Tweet和Tweet的好方法是什么。
页位于PHP服务器上。
编辑
我只想在这样的页面上展示最后一条推特。
<div id="last-tweet">
<p>Content of tweet here</p>
</div>发布于 2011-02-20 04:03:17
使用Twitter REST API。
$api_url = 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=USERNAME';
$twitter_data = file_get_contents($api_url);
$twitter_data = json_decode($twitter_data);
echo '<div id="last-tweet"><p>' . $twitter_data[0]->text . '</p></div>';用您的用户名替换USERNAME。
http://dev.twitter.com/doc#rest-api
http://php.net/file-get-contents
http://php.net/json-decode
发布于 2012-10-03 05:45:38
在Jonah回答的基础上,下面是如何做完全相同但自动链接到其他提到的用户和链接的方法:
$api_url = 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=YOURUSERNAME';
$twitter_data = file_get_contents($api_url);
$twitter_data = json_decode($twitter_data);
$tweet = '<div id="last-tweet"><p>' . $twitter_data[0]->text . '</p></div>';
// Turn URLs into links
$tweet = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $tweet);
// Turn @replies into links
$tweet = preg_replace("/@([0-9a-zA-Z]+)/", "<a href=\"http://twitter.com/$1\">@$1</a>", $tweet);
echo $tweet;https://stackoverflow.com/questions/5055146
复制相似问题