0

我正在使用 twitterizer 在网站上显示推文,但问题是显示所有推文,我只想显示用户的推文而不是回复,我使用的代码是:

if (!Page.IsPostBack)
        {
            try
            {

            UserTimelineOptions options = new UserTimelineOptions();
            options.ScreenName = "XXXXX";

            TwitterStatusCollection tweets = TwitterTimeline.UserTimeline(options).ResponseObject;
            int counter = 0;
            string TwitterCode = "";     

            foreach (TwitterStatus thisStatus in tweets)
            {
                if (counter < 7)
                {
                    DateTime completeDate = thisStatus.CreatedDate;
                    string complete = completeDate.ToLongDateString();
                    TwitterCode += "<li><p ><a href=\"http://twitter.com/" + thisStatus.User.ScreenName + "\" target=\"_blank\" >" + Server.HtmlEncode(thisStatus.Text) + "<br/><span style=\"color:#E87D05;\">" +  complete + "</a></p></li>";
                    counter += 1;

                }
                else
                {
                    break;
                }

            }

            ltlTweets.Text = TwitterCode;


        }
        catch (Exception ex)
        {

        }

        }

上面的代码工作正常,但我想避免回复,我该怎么做我已经浏览了 twitteriser 的文档但找不到任何解决方案,任何建议或帮助将不胜感激谢谢

4

1 回答 1

0

The UserTimeLineOptions object allows you to exclude retweets vie the IncludeRetweets property. Like so:

UserTimelineOptions options = new UserTimelineOptions()
{
    ScreenName = "myname",
    UserId = 123456789,
    IncludeRetweets = false,
    Count = 10,
};

The UserId helps the twitterAPI figure out that you are only requesting tweets made by that specific combination of UserId and ScreenName (i.e your account).

I'm not sure if it is completely necessary, but I also send an OAuthTokens object in with the request.

OAuthTokens token = new OAuthTokens()
{
    AccessToken = "xx",
    AccessTokenSecret = "xx",
    ConsumerKey = "xx",
    ConsumerSecret = "xx"
};

You would get hold of this information by creating an app under your twitter account at http://dev.twitter.com.

Then you would include the token in your call:

TwitterTimeline.UserTimeline(token, options);

Hope this helps =)

于 2013-04-03T14:45:14.763 回答