显示用户Twitter帐户页面上的所有推文

时间:2010-12-14 10:30:53

标签: php asp.net jquery twitter

我已经使用用户时间线显示特定用户发布的所有推文,但我想要实现的是显示我的网站上用户制作或接收的所有推文。

有没有办法实现它。

2 个答案:

答案 0 :(得分:1)

因此,您希望获得用户发布的所有推文以及提及用户(又称发送给用户)的所有推文?

第一次见,

http://dev.twitter.com/doc/get/statuses/public_timeline

对于第二个看,

http://dev.twitter.com/doc/get/statuses/mentions

您需要使用OAuth身份验证来访问后面的API调用。

答案 1 :(得分:0)

我最近写了一些东西。希望这可以帮助。 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);
            }
        }
    }
}