如何在用户级别的日期范围内获得所有未接受的答案?

How can I get all the unaccepted answers within a date range at user level?

我可以使用下面的 curl 命令检索给定日期范围内所有答案的列表:

curl "https://api.stackexchange.com/2.2/users/10348758/answers?page=1&pagesize=100&fromdate=1588291200&todate=1592179200&order=desc&sort=activity&site=Whosebug&access_token=my-access-token&key=my-key" | gunzip

我需要找到给定日期范围内我未接受的答案的列表。

根据文档,these 字段可应用于答案类型。

文档中写道:

The upvoted, downvoted, and accepted fields can only be queried for with an access_token with the private_info scope.

因此,我还创建了 access_token,范围为 private_info

我按以下方式修改了我的命令:

curl "https://api.stackexchange.com/2.2/users/10348758/answers?is_accepted=false?page=1&pagesize=100&fromdate=1588291200&todate=1592179200&order=desc&sort=activity&site=Whosebug" | gunzip

在上面的命令中,我添加了 is_accepted=false 参数,但我得到的结果与上面的命令相同,即我得到了完整的答案列表。我只想检索我的那些未被接受的答案(在给定的日期范围内)。我需要在 curl 命令中应用过滤器吗?

如何使用 Stack Exchange API 检索我所有未接受的答案的列表(在给定的日期范围内)?

is_accepted 是字段之一。而且,在目前阶段,这似乎不能用于过滤结果值作为查询参数。

从这种情况来看,下面的解决方法怎么样?我想建议使用 jq 来过滤检索到的值。在此解决方法中,使用 jq.

从所有检索到的值中检索具有 is_accepted: false 的值

示例命令:

curl "https://api.stackexchange.com/2.2/users/10348758/answers?page=1&pagesize=100&fromdate=1588291200&todate=1592179200&order=desc&sort=activity&site=Whosebug&access_token=my-access-token&key=my-key" | gunzip | jq '[.items[] | select(.is_accepted == false)]'
  • 在这种情况下,jq '[.items[] | select(.is_accepted == false)]' 用于检索值。
  • 通过此修改,检索带有 "is_accepted": false 的值。

注:

  • 在此修改中,假设您的访问令牌和密钥可用于请求 https://api.stackexchange.com/2.2/users/10348758/answers

参考文献: