在使用Stack Exchange 2.2 API时,我在使用post_ids
检索数据时遇到了障碍。我的结果不完整。
根据posts/{ids}
界面的在线文档, 我应该能够检索 30 个问题。(它说最多 100,但其他查询的最大值为 30,所以我认为这也会。
但是,使用此查询("查询 1"(:
/2.2/员额/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 结果
["项目": [
["creation_date": 2017-06-30 15:41:31 +0000, "link": 如何在 Objective-C 中解包 XML 中的内容值, "score": -1, "post_type": 星期三.PostType.question, "last_activity_date": 2017-07-03 13:57:21 +0000, "所有者": ["链接": https://www.gravatar.com/avatar/e0616f34ea00d07842b7e7886fd7abc8?s=128&d=identicon&r=PG&f=1, "user_type": 星期三.User.UserType.register, "user_id": 7707593, "display_name": "史蒂文", "声誉": 18, "accept_rate": 75], "last_edit_date": 2017-07-03 07:41:31 +0000],
["creation_date": 2017-07-02 15:25:37 +0000,"链接": 如何收集函数的返回值 (Swift 3(, "score": -4, "post_type": 星期三.PostType.question, "last_activity_date": 2017-07-02 15:43:58 +0000, "所有者": ["链接": https://lh6.googleusercontent.com/-NIYQgyduM8w/AAAAAAAAAAI/AAAAAAAAAaQ/e0IACRo6xbI/photo.jpg?sz=128, "user_type": 星期三.User.UserType.register, "user_id": 6298390, "display_name": "多利安·布朗", "声誉": 18, "accept_rate": 100], "last_edit_date": 2017-07-02 15:43:58 +0000],
["creation_date": 2017-06-30 19:02:07 +0000,"链接": swift - 用于纠结/横切代码(日志记录、分析等(的方法,"score":0,"post_type": 星期三.PostType.question, "last_activity_date": 2017-07-01 01:26:24 +0000, "所有者": ["链接": https://www.gravatar.com/avatar/e819b2408e9528b895dc192aee309912?s=128&d=identicon&r=PG&f=1, "user_type": 星期三.用户.用户类型.注册, "user_id": 108546, "display_name": "拉文", "声誉": 743, "accept_rate": 86], "last_edit_date": 2017-07-01 01:26:24 +0000]
],
"quota_remaining": 221,
"quota_max":300,"has_more":假]
注意"has_more":false,所以 API 认为它已经提供了所有信息。
使用此查询("查询 2"(:
/2.2/帖子/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 个条目。这些都是有效的身份证件
(LLDB( PO 结果
["quota_max": 300, "quota_remaining": 224, "has_more":假]
以下是一些用于调用的 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 不会返回已删除的帖子。 有一个功能请求,你可能想去投票。
但是,API 中返回的已删除帖子存在错误,因此您可能会暂时看到一些已删除的帖子,以及您不应该看到的已删除帖子。
另请注意,作为少于 10K 的用户,理论上除非您是作者,否则您永远无法看到已删除的帖子。
在您的文档链接中,您有 3 个 ID(3743、327738 和 339426(:
- 但是它只返回339426。
- 帖子 374310K 链接被删除。
- 但是帖子327738是有效的!
这可能是一个严重的错误。
在"查询 1"中,除了最后 3 个帖子外,所有帖子都将被删除,因此API 将返回正确的条目。
在您的"查询 2"中,所有 30 个帖子都将被删除,因此API 是正确的,不返回任何内容。
回复:"有更新的 API 吗?
不。 不是正式的。
非正式地,3.0 版的工作似乎已经开始,但它远未准备好使用。