如何获取用户的新闻Feed,就像他们在Twitter上看到的一样。我正在一个用户登录到Twitter的网站上工作,页面会显示他们的提要,而不会进入推特。
答案 0 :(得分:1)
请参阅此snipet示例:
<?php
$fname = "../tmp/twitter.cache.html";
// Sistema de cache - tentando recuperar
if (file_exists($fname)) {
if (time() - filemtime($fname) < 240) {
echo file_get_contents($fname);
exit;
}
}
ob_start();
?>
<style>
ul li {
list-style:none;
}
</style>
<?php
$url = 'https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=unilogica&count=35';
$xml = @simplexml_load_file($url);
$twitter = @json_decode(file_get_contents("http://api.twitter.com/1/users/show.json?screen_name=unilogica"));
$avatar = $twitter->profile_image_url;
if (!isset($xml->channel->item)) {
echo "<center>Oops, Twitter instavel...</center>";
exit;
}
foreach(@$xml->channel->item as $node){
$node->title = substr($node->title, 10);
$offset = strpos($node->title, ' RT @');
if ($offset !== false) {
$screen_name = substr($node->title, $offset+5, strpos($node->title, ':', 2) - $pos - 5);
$twitter = json_decode(file_get_contents("http://api.twitter.com/1/users/show.json?screen_name=$screen_name"));
$node->title = str_replace(" RT @$screen_name:", "<img width=\"32\" height=\"32\" align=\"left\" src=\"{$twitter->profile_image_url}\">", $node->title);
} else {
$node->title = "<img width=\"32\" height=\"32\" align=\"left\" src=\"{$avatar}\"> ".$node->title;
}
echo '<ul>';
printf('<li><div class="twitter-msg-container"><a href="%s" style="color:#069; font-family: arial, verdana, helvetica, sans-serif;" target="_blank">%s</a></div></li>',
$node->link,
$node->title
);
echo '</ul>';
}
$buffer = ob_get_clean();
@file_put_contents($fname, $buffer);
echo $buffer;
答案 1 :(得分:0)
这应该有帮助,只需更改用户名,它就会以json格式为您提供Twitter Feed。
<script type="text/javascript" src="http://api.twitter.com/1/statuses/user_timeline.json?callback=twitterCallback2&count=2&include_rts=true&screen_name=TWITTERUSERNAME"></script>
答案 2 :(得分:0)