错误检索使用堆叠交换API
与堆栈交易所2.2 API的使用多个ID,使用post_ids
当检索数据我遇到了一个障碍。我的结果不完整。错误检索使用堆叠交换API
根据the online documents for the posts/{ids}
interface, 我应该能够检索30个问题。 (报告说,多达100个,但其他的查询在30杏,所以我相信这会为好。)
但是,使用此查询( “查询1”):
我回来刚好3条,那些是:44850293; 44872388;和44853254.
(LLDB)PO结果
[ “项”:[
[ “CREATION_DATE”:2017年6月30日十五点41分31秒 0000, “链接” :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”: “史蒂芬”, “信誉”:18, “accept_rate”:75], “LAST_EDIT_DATE”:2017年7月3日7点41分31秒0000],
[ “CREATION_DATE”: 2017年7月2日15时25分37秒0000, “链接”: How to collect the return value of a function (Swift 3)“分数“:-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”: “道连布朗”, “信誉”:18, “accept_rate”:100], “LAST_EDIT_DATE”:2017年7月2日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年7月1日1时26分24秒0000]
],
“quota_remaining”:221,
“q uota_max“:300, ”has_more“:假]
通知”has_more“:假 - 这样的API认为它提供的所有信息。
使用此查询( “查询2”):
我回来0项。这些都是有效的ID
(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不会返回已删除的帖子。有a feature request for this,你可能想要得到它。
然而,deleted posts return in the API is buggy,所以你可能暂时看到一些删帖,以及deleted posts that you're not supposed to be able to。
另请注意,作为一个用户少于10K,理论上你应该永远不会看到删除的帖子,除非你是作者。
在your doc link,你有3个IDS(3743,327738和339426):
- 但它只返回339426.
- Post 3743 10K link被删除。
- 但是Post 327738 is valid!
这可能是一个严重的错误。
在你的“查询1”,除了最后3个帖子被删除,所以该API返回正确的条目。
在您的“查询2”中,所有30个帖子都被删除,所以的API是正确的,不返回任何内容。
回复:“有没有更新的API?”
不是。
非正式地说,工作似乎已经从版本3.0开始,但它远没有准备好使用。
让我从“谢谢”开始,并进行投票。我一直在假设post_ids是永久性的,并且一直在将这些感兴趣的内容保存在Realm db中供以后研究(我可以回答的事情,可能“最喜欢的”等等)。我是否应该使用question_id? ?如果我手动保存的8K ID被删除,是否有链接到我感兴趣的方式:原始问题(通常,post_id和title可以为我提供一个url - 如果url没有被删除。)我应该创建一个新问题,询问如何存储指向有趣帖子的指针? – Mozahler
'post_id's * *是永久性的。只是我们较小的凡人不能总是看到它们。 ;)...如果帖子是一个问题,'question_id'和'post_id'是相同的。使用'post_id'很好(不包括错误)。 ...您可以将任何帖子,甚至是答案链接到像“https:// stackoverflow.com/q/327738”这样的URL。如果'/ q /'后面的帖子ID是答案,它仍然可以正常工作,但是会重定向到一个像'https:// stackoverflow.com/questions/327654/hashtable-to-dictionary-syncroot/327738#327738# 。但是,如果该帖子被删除,您将无法看到它,直到您获得10K。但'SEDE'已删除帖子。 –
再次感谢!我正在写一个关于“需要保存什么”的新问题,以便稍后返回到帖子。 – Mozahler