10

我想使用Stacky C# library for the Stack Exchange API从Stack Overflow获取最新的问题。

我采用了示例代码并尝试运行它,但在从Stack Exchange网站返回数据时它挂起。

StackyClient client = new StackyClient("0.9", "", Sites.StackOverflow, 
            new UrlClient(), new JsonProtocol());

var o = new QuestionOptions();
o.FromDate = DateTime.Now.AddMinutes(-10.0);
o.ToDate = DateTime.Now;
o.IncludeAnswers = false;
o.IncludeBody = false;
o.IncludeComments = false;
o.SortBy = QuestionSort.Creation;
o.SortDirection = SortDirection.Descending;

IPagedList<Question> l = client.GetQuestions(o); <--- program hangs here 4ever

我究竟做错了什么?

我还看到我可以注册我的应用程序以获取API Key。但这并不是让它首先运行的必要条件,不是吗?

编辑

如果我删除线条

o.FromDate = DateTime.Now.AddMinutes(-10.0);
o.ToDate = DateTime.Now;

它工作并返回所有问题。另外,如果我添加该行

o.Max = 50;

相反,它也不起作用。

编辑 2

现在它可以工作了 -重新启动了我的计算机
顺便说一句,我最后使用了该代码

var o = new QuestionOptions();
o.FromDate = DateTime.UtcNow.AddMinutes(-20);
o.IncludeAnswers = false;
o.IncludeBody = false;
o.IncludeComments = false;
o.SortBy = QuestionSort.Creation;
o.SortDirection = SortDirection.Descending;

IPagedList<Question> l = client.GetQuestions(o);

o.Max

期望 Unix 纪元时间,而不是最大帖子数。

4

2 回答 2

4

尝试将StackyClient构造函数中指定的版本从“0.9”更改为“1.1”。当版本为“0.9”时,我在线路上收到 JSON 解析错误client.GetQuestions(o),但它在“1.1”时运行良好。

于 2013-04-26T17:20:55.640 回答
0

使用来自bitbucket的最新 Stacky 代码,GetQuestions 不再有 QuestionOptions 参数。同样使用 API 的 0.9 版本会导致 Stacky 崩溃,但根据这个版本 1.x 已被弃用,所以也许 0.9 被删除了?

  StackyClient client = new StackyClient("2.1", Sites.StackOverflow,
        new UrlClient(), new JsonProtocol());
  //var o = new QuestionOptions();
  //o.FromDate = DateTime.Now.AddMinutes(-10.0);
  //o.ToDate = DateTime.Now;
  //o.IncludeAnswers = false;
  //o.IncludeBody = false;
  //o.IncludeComments = false;
  //o.SortBy = QuestionSort.Creation;
  //o.SortDirection = SortDirection.Descending;
  QuestionSort sort = QuestionSort.Creation;
  SortDirection sortDir = SortDirection.Descending;
  int page = 1;
  int pageSize = 100;
  DateTime fromDate = DateTime.Now.AddMinutes(-10.0);
  DateTime toDate = DateTime.Now;
  IPagedList<Question> l = client.GetQuestions(sort, sortDir, page, pageSize, fromDate, toDate);
  foreach (var question in l)
  {
    Console.WriteLine(question.Title);
  }

或者,只需删除日期,看看是否有任何结果。

  IPagedList<Question> l = client.GetQuestions(sort, sortDir, page, pageSize);//, fromDate, toDate);
  foreach (var question in l)
  {
    Console.WriteLine(question.Title);
  }
于 2013-05-03T23:47:41.443 回答