从帖子编号到帖子ID

两年前我就急需同样的功能。我至今仍未找到更恰当的实现方法。这是我的变通方案:

def get_topic_post(topic_id, post_num)
    topic = @api.topic(topic_id, {print: true})
    post_obj = topic['post_stream']['posts'].find { |p| p['post_number'] == post_num }
    if post_obj
        post_obj['id']
    else
        throw "Could not find post #{topic_id}/#{post_num}."
    end
end

这规避了前述问题:{print: true} 解决了分页问题。而 find 是必要的,因为审核操作可能导致数组索引与帖子编号不匹配。

对于我所处理的帖子规模,这个方法有效。不过,如果能通过 API 找到更直接的方式,会更令人满意。