2013-02-16 74 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); 
      } 
     } 
    } 
} 
相关问题