【问题标题】:Unauthorized Twitter Stream Sample未经授权的 Twitter 流示例
【发布时间】:2013-11-12 02:45:53
【问题描述】:

我正在尝试使用 LinqToTwitter 学习 Twitter API。它可以很好地连接到 Twitter API,但不能连接到 Twitter Stream。据我所知,我需要特殊权限才能访问消防站,但应该可以访问样本流和过滤器流。如果这是真的,我似乎无法理解为什么使用以下代码得到“401 Unauthorized”:

        var auth = new ApplicationOnlyAuthorizer
    {
        Credentials = new InMemoryCredentials
        {
            ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"],
            ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"],
        }
    };

    auth.Authorize();

    var twitterCtx = new TwitterContext(auth);

    int count = 0;
    string response = "";
    (from strm in twitterCtx.Streaming
     where strm.Type == StreamingType.Filter &&
         strm.Track == query
     select strm)
    .StreamingCallback(strm =>
    {
        if (strm.Status != TwitterErrorStatus.Success)
        {
            Console.WriteLine(strm.Error.ToString());
            return;
        }

        response += "<p>" + strm.Content + "</p>";

        if (count++ >= 2)
        {
            strm.CloseStream();
        }
    })
    .SingleOrDefault();

【问题讨论】:

    标签: twitter linq-to-twitter


    【解决方案1】:

    Twitter 流不支持仅应用程序授权。尝试 SingleUserAuthorizer。此外,401 错误的发生可能有多种原因,您可以查看LINQ to Twitter FAQ 寻求帮助。

    【讨论】:

      猜你喜欢
      • 2014-01-02
      • 2015-09-15
      • 1970-01-01
      • 2013-08-22
      • 2012-06-24
      • 2012-04-08
      • 1970-01-01
      • 2013-06-15
      • 2016-12-24
      相关资源
      最近更新 更多