使用 disqusapi 模块列出 disqus 线程时如何使用指定 'since' 值?

How to use specify a 'since' value when listing disqus threads with disqusapi module?

我正在使用 disqusapi Python 模块访问 Disqus 的 API。我想使用 since 参数,只获取自我指定日期以来创建的线程列表。但是,当我传递一个值时,我什么也得不到。

SECRET_KEY = config.get("disqus-keys", "private")
PUBLIC_KEY = config.get("disqus-keys", "public")    
disqus = DisqusAPI(SECRET_KEY, PUBLIC_KEY)

....

# Ask for all threads since 4 years ago.
t = int(time.time()) - 60*60*24*365*4
results = disqus.threads.list(forum="imaginaryrealities", limit=100, since=t)
print "with since=%d, got %d threads" % (t, len(results))
results = disqus.threads.list(forum="imaginaryrealities", limit=100)
print "with no since, got %d threads" % len(results)
timeseq = list(time.strptime(results[0]["createdAt"], '%Y-%m-%dT%H:%M:%S'))
timeseq.append(0) # offset of date's timezone from UTC.
timeseq = tuple(timeseq)
rt = email.utils.mktime_tz(timeseq) # UTC seconds since the epoch
print "... first thread created at: %s (greater than %d? %s)" % (rt, t, rt > t)

给出以下输出:

with since=1311988086, got 0 threads
with no since, got 30 threads
... first thread created at: 1437988189 (greater than 1311988086? True)

我什至尝试过将 1311988086 转换成与 disqus 相同的 RFC3339 字符串,并传递它的日期,结果相同。

官方之一PHP samples passes in the "seconds since the epoch" value. The official API "documentation" is no help whatsoever.

为什么这不起作用?

也尝试设置 order='asc'since 参数与排序顺序相关,因此它正在查找比该日期时间 更早 的任何内容。

您需要以 RFC3339 格式传递时间以及 order = asc。例如

https://disqus.com/api/3.0/forums/listPosts.json?api_key=[api_key]&forum=[forum]&since=2015-08-10T20:00:00&order=asc

我建议使用 disqus api cursor 而不是 since 参数。使用 since 时出现重复(即第一个查询的最后结果出现在第二个查询的第一个结果中)。无论我是在新时间戳上加一秒还是加 30 分钟都没关系,它总是那样做。

cursor是响应体的数据成员,文档:

https://disqus.com/api/docs/cursors/

使用游标时它工作可靠。