2013-02-16 76 views

回答

1

一個,你會面對的問題是使用OAuth的需要在Twitter API v1.1所需的所有查詢上。 Twitter已棄用API的v1.0版,並將在下個月關閉之前開始停電。我在Twitter的網頁上看不到任何網頁小部件也要這樣做。

如果將其嵌入網頁中,則需要JavaScript OAuth庫,這也意味着您的憑證必須位於您的網頁中 - 這是一種不安全的方法。

Silverlight是一種可能性,但微軟對HTML/JavaScript的關注使得它的未來處於可疑狀態。此外,有人還可以反編譯組件並獲取您的憑據,這也不安全。

這使服務器端解決方案成爲最佳可能。你可以通過拉或推處理。 SignalR將是一種推動的好方法,但是權衡是你需要一個持續運行的過程來立即更新。如果您運行自己的服務器,則可以通過Windows Service運行一個進程,該進程可以執行定期搜索查詢,也可以使用Filter Stream並使用SignalR將結果推送到頁面。在pull方法中,您的頁面可以將帶有Ajax查詢的計時器運行回服務器,收集新的推文並在頁面上顯示它們。這些只是一對夫婦的想法,但提供給你一個你如何解決問題的想法。

Twitter有一個Libraries您可以使用的列表。我寫了LINQ to Twitter,它也支持Twitter API v1.1。

2

您可以創建一個embedded timeline或者你可以嘗試live tweet - 一個jQuery插件

+0

我會用這個。現場推文將持續刷新客戶端 – amhed 2013-02-16 20:34:09

1

我最近寫了一些東西。希望這可以幫助。 http://blog.rohit-lakhanpal.info/2013/06/console-app-that-displays-twitter-feed.html

using System; 
using System.Linq; 
using LinqToTwitter; 
using System.Threading; 

namespace Linq2Twitter 
{ 
    class Program 
    { 
     /// <summary> 
     /// Controls the flow of the program. 
     /// </summary> 
     /// <param name="args">The args.</param> 
     static void Main(string[] args) 
     { 
      // This is a super simple example that 
      // retrieves the latest tweets of a given 
      // twitter user. 

      // SECTION A: Initialise local variables 
      Console.WriteLine("SECTION A: Initialise local variables"); 

      // Access token goes here .. (Please generate your own) 
      const string accessToken = "Access token goes here .. (Please generate your own)"; 
      // Access token secret goes here .. (Please generate your own) 
      const string accessTokenSecret = "Access token secret goes here .. (Please generate your own)"; 

      // Api key goes here .. (Please generate your own) 
      const string consumerKey = "Api key goes here .. (Please generate your own)"; 
      // Api secret goes here .. (Please generate your own) 
      const string consumerSecret = "Api secret goes here .. (Please generate your own)"; 

      // The twitter account name goes here 
      const string twitterAccountToDisplay = "roeburg"; 


      // SECTION B: Setup Single User Authorisation 
      Console.WriteLine("SECTION B: Setup Single User Authorisation"); 
      var authorizer = new SingleUserAuthorizer 
      { 
       CredentialStore = new InMemoryCredentialStore 
       { 
        ConsumerKey = consumerKey, 
        ConsumerSecret = consumerSecret, 
        OAuthToken = accessToken, 
        OAuthTokenSecret = accessTokenSecret 
       } 
      }; 

      // SECTION C: Generate the Twitter Context 
      Console.WriteLine("SECTION C: Generate the Twitter Context"); 
      var twitterContext = new TwitterContext(authorizer); 

      // SECTION D: Get Tweets for user 
      Console.WriteLine("SECTION D: Get Tweets for user"); 
      var statusTweets = from tweet in twitterContext.Status 
           where tweet.Type == StatusType.User && 
             tweet.ScreenName == twitterAccountToDisplay && 
             tweet.IncludeContributorDetails == true && 
             tweet.Count == 10 && 
             tweet.IncludeEntities == true 
           select tweet; 

      // SECTION E: Print Tweets 
      Console.WriteLine("SECTION E: Print Tweets"); 
      PrintTweets(statusTweets); 
      Console.ReadLine(); 
     } 

     /// <summary> 
     /// Prints the tweets. 
     /// </summary> 
     /// <param name="statusTweets">The status tweets.</param> 
     /// <exception cref="System.NotImplementedException"></exception> 
     private static void PrintTweets(IQueryable<Status> statusTweets) 
     { 
      foreach (var statusTweet in statusTweets) 
      { 
       Console.WriteLine(string.Format("\n\nTweet From [{0}] at [{1}]: \n-{2}", 
        statusTweet.ScreenName, 
        statusTweet.CreatedAt, 
        statusTweet.Text)); 

       Thread.Sleep(1000); 
      } 
     } 
    } 
} 
相關問題