使用 Stack Exchange API 检索多个 ID 时出错

Error retrieving multiple ids using the Stack Exchange API

使用 Stack Exchange 2.2 API,我在使用 post_ids 检索数据时遇到了 运行 障碍。我的结果不完整。

根据the online documents for the posts/{ids} interface, 我应该能够检索 30 个问题。 (它说最多 100 个,但其他查询最大为 30 个,所以我认为这也是如此。)

但是,使用此查询 ("Query 1"):

/2.2/posts/44697152;44725527;44740511;44740358;44746963;44744722;44752663;44751224;44750591;44768116;44768073;44766268;44762034;44763620;44763575;44763124;44778755;44782321;44792568;44791709;44791955;44801095;44800945;44808174;44809993;44801579;44838390;44872388;44853254;44850293

我正好找回了 3 个条目,它们是:44850293; 44872388;和 44853254。

(lldb) po result

["items": [

["creation_date": 2017-06-30 15:41:31 +0000, "link": , "score": -1, "post_type": Wednesday.PostType.question, "last_activity_date": 2017-07-03 13:57:21 +0000, "owner": ["link": https://www.gravatar.com/avatar/e0616f34ea00d07842b7e7886fd7abc8?s=128&d=identicon&r=PG&f=1, "user_type": Wednesday.User.UserType.registered, "user_id": 7707593, "display_name": "Steven", "reputation": 18, "accept_rate": 75], "last_edit_date": 2017-07-03 07:41:31 +0000],

["creation_date": 2017-07-02 15:25:37 +0000, "link": , "score": -4, "post_type": Wednesday.PostType.question, "last_activity_date": 2017-07-02 15:43:58 +0000, "owner": ["link": https://lh6.googleusercontent.com/-NIYQgyduM8w/AAAAAAAAAAI/AAAAAAAAAaQ/e0IACRo6xbI/photo.jpg?sz=128, "user_type": Wednesday.User.UserType.registered, "user_id": 6298390, "display_name": "Dorian Brown", "reputation": 18, "accept_rate": 100], "last_edit_date": 2017-07-02 15:43:58 +0000],

["creation_date": 2017-06-30 19:02:07 +0000, "link": swift - approach for tangled/cross-cutting code (logging, analytics, etc.), "score": 0, "post_type": Wednesday.PostType.question, "last_activity_date": 2017-07-01 01:26:24 +0000, "owner": ["link": https://www.gravatar.com/avatar/e819b2408e9528b895dc192aee309912?s=128&d=identicon&r=PG&f=1, "user_type": Wednesday.User.UserType.registered, "user_id": 108546, "display_name": "ravun", "reputation": 743, "accept_rate": 86], "last_edit_date": 2017-07-01 01:26:24 +0000]

],

"quota_remaining": 221,

"quota_max": 300, "has_more": false]

注意"has_more": false -- 所以API认为它已经提供了所有信息。

使用此查询 ("Query 2"):

/2.2/posts/44218623;44217105;44262473;44272520;44309003;44305981;44319988;44318730;44330107;44329638;44334480;44350820;44354106;44358187;44374565;44374073;44365138;44377970;44388874;44395390;44397545;44401141;44399160;44408394;44454372;44446876;44458876;44461402;44468764;44650412

我找回了 0 个条目。 这些都是有效的 ID

(lldb) po result

["quota_max": 300, "quota_remaining": 224, "has_more": false]

这里是一些用于调用的 Swift 3.2 代码的示例(我不认为 swift 代码是问题所在):

let response: String = try get(url)
guard let json = try parseJSON(response) as? [String:Any] else {
    throw APIError.notDictionary(response: response)
}

open func get(_ url: String) throws -> (Data, HTTPURLResponse) {
    guard let nsUrl = URL(string: url) else {
        throw RequestError.invalidURL(url: url)
    }
    var request = URLRequest(url: nsUrl)
    request.setValue(String(request.httpBody?.count ?? 0), forHTTPHeaderField: "Content-Length")
    return try performRequest(request)
}

如何使用 2.2 API 检索包含 30 个帖子的列表? 有更新的API吗?

最重要的是 API 不会 return 删除帖子 。有a feature request for this,你可能想给它投票。

不过, deleted posts return in the API is buggy, so you might temporarily see some deleted posts, as well as deleted posts that you're not supposed to be able to.

另请注意,作为拥有少于 10K 的用户,理论上您永远无法看到已删除的帖子,除非您是作者。

your doc link 中,您有 3 个 ID(3743、327738 和 339426):

  • 然而它只有 returns 339426。
  • Post 3743 10K link 已删除。
  • 但是Post 327738 is valid!

这可能是一个严重的错误。


在您的 "Query 1" 中,除最后 3 个帖子外的所有帖子都被删除,因此 API return 是正确的条目。

在你的"Query 2"中,所有30个帖子都被删除了,所以API是正确的return没有。


回复:"Is there a newer API?"

没有。非官方。
非正式地,3.0 版的工作似乎已经开始,但还远未准备好使用。