與堆棧交易所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?
讓我從「謝謝」開始,並進行投票。我一直在假設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