Working with the Stack Exchange 2.2 API, I have run into a roadblock when using post_ids
to retrieve data. My results are incomplete.
According the online documents for the posts/{ids}
interface,
I should be able to retrieve 30 questions. (It says up to 100, but other queries are maxing out at 30, so I assume this would as well.)
But, using this query ("Query 1"):
I get back exactly 3 entries, those for: 44850293; 44872388; and 44853254.
(lldb) po result
["items": [
["creation_date": 2017-06-30 15:41:31 +0000, "link": How to unwrap the content value from XML in Objective-C, "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": How to collect the return value of a function (Swift 3), "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]
Notice "has_more": false -- so the API thinks it has provided all the information.
Using this query ("Query 2"):
I get back 0 entries. These are all valid ids
(lldb) po result
["quota_max": 300, "quota_remaining": 224, "has_more": false]
Here is a sample of some the Swift 3.2 code used to call (I don't believe the swift code is the issue):
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)
}
How do I retrieve a list of 30 posts using the 2.2 API? Is there a newer API?