【问题标题】:Using Twitterizer to display the outbound tweets, not replies使用 Twitterizer 显示出站推文,而不是回复
【发布时间】:2013-02-06 19:05:25
【问题描述】:

我使用 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 的文档但找不到任何解决方案,任何建议或帮助将不胜感激 谢谢

【问题讨论】:

    标签: c# twitter twitterizer


    【解决方案1】:

    UserTimeLineOptions 对象允许您通过IncludeRetweets 属性排除转发。像这样:

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

    UserId 帮助 twitterAPI 确定您只请求由 UserId 和 ScreenName 的特定组合(即您的帐户)发出的推文。

    我不确定这是否完全有必要,但我也会在请求中发送一个OAuthTokens 对象。

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

    您可以通过在您的 Twitter 帐户http://dev.twitter.com 下创建一个应用程序来获取此信息。

    然后你会在你的调用中包含令牌:

    TwitterTimeline.UserTimeline(token, options);
    

    希望这会有所帮助 =)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多