2013-01-21 69 views
-2

如何獲取用戶的新聞提要,就像他們在Twitter上看到的一樣。我正在使用用戶登錄到Twitter的網站上工作,並且該頁面向他們顯示了他們的Feed,而不需要他們去推特。如何獲取推特新聞Feed

+0

我猜你正在尋找這個https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline – Ragnarokkr

+0

你看了什麼Twitter的API? https://dev.twitter.com/docs/api/1/get/statuses/user_timeline – epascarello

+1

對於剪切和粘貼小部件:twitter.com/about/resources/widgets – Mooseman

回答

0

這應該有所幫助,只需更改用戶名,它會以json格式爲您提供Twitter提要。

<script type="text/javascript" src="http://api.twitter.com/1/statuses/user_timeline.json?callback=twitterCallback2&amp;count=2&amp;include_rts=true&amp;screen_name=TWITTERUSERNAME"></script> 
+0

API v1將被棄用。最好更新到1.1的URL。 – Ragnarokkr

0

您可以使用小部件來做到這一點。 Twitter有一個非常簡單的小部件系統,您可以在其中嵌入Twitter feed到網站。查看here

還有this,它使用jQuery和風格Twitter的飼料相當不錯。

但是請在轉向StackOverflow之前先進行Google搜索。任何人都可以在Google搜索結果的兩秒鐘內找到我提供的鏈接。

+0

但是這個小部件並沒有解決我的問題。該小部件只顯示我發佈,收藏或轉推的內容,但我希望看到我關注的人以及我自己的活動發出的所有推文 – evanoc

+0

因此幾乎在您的網站上加載了他們的整個Twitter提要? – Charles

+0

是的,我希望他們的整個飼料顯示 – evanoc

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;