news 2026/3/11 4:46:01

飞书知识库备份

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
飞书知识库备份

目录

1、创建应用,添加机器人能力,添加应用为知识库管理员。方法如图:

2、获取到知识空间ID。

3、Java代码(递归调用)


1、创建应用,添加机器人能力,添加应用为知识库管理员。方法如图:

2、获取到知识空间ID。

3、Java代码(递归调用)

package xyz.jangle.feishu.test; import java.io.File; import java.nio.charset.StandardCharsets; import java.util.concurrent.TimeUnit; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.google.gson.JsonParser; import com.lark.oapi.Client; import com.lark.oapi.core.utils.Jsons; import com.lark.oapi.service.drive.v1.model.DownloadFileReq; import com.lark.oapi.service.drive.v1.model.DownloadFileResp; import com.lark.oapi.service.wiki.v2.model.ListSpaceNodeReq; import com.lark.oapi.service.wiki.v2.model.ListSpaceNodeResp; /** * 知识空间(知识库)备份 * @author jangle * @email 274676957@qq.com * 2025年12月17日 上午10:38:34 */ public class FeishuZSKMain { Client client; public FeishuZSKMain() { super(); client = Client.newBuilder("App ID", "App Secret").build(); } /** * 1.遍历知识库 * 2025年12月17日 上午11:03:47 @author jangle * @param spaceId 知识空间ID * @param parentNodeToken 上级token * @param path 文件路径 * @throws Exception */ public void getListSpaceNode(String spaceId,String parentNodeToken,String path,String pageToken) throws Exception { // 创建请求对象 ListSpaceNodeReq req = ListSpaceNodeReq.newBuilder() .spaceId(spaceId) .pageSize(50) .pageToken(pageToken) .parentNodeToken(parentNodeToken) .build(); // 发起请求 ListSpaceNodeResp resp = client.wiki().v2().spaceNode().list(req); // 处理服务端错误 if (!resp.success()) { System.out.println(String.format("code:%s,msg:%s,reqId:%s, resp:%s", resp.getCode(), resp.getMsg(), resp.getRequestId(), Jsons.createGSON(true, false).toJson(JsonParser.parseString(new String(resp.getRawResponse().getBody(), StandardCharsets.UTF_8))))); return; } // 业务数据处理 // System.out.println(Jsons.DEFAULT.toJson(resp.getData())); String json = Jsons.DEFAULT.toJson(resp.getData()); JSONObject data = JSONObject.parseObject(json); JSONArray items = data.getJSONArray("items"); for (int i = 0; i < items.size(); i++) { JSONObject item = items.getJSONObject(i); if(item.getBoolean("has_child")) { // 有子集,则向下遍历 // System.out.println("has_child:"+item.getBoolean("has_child")); // System.out.println("obj_token:"+item.getString("obj_token")); // System.out.println("title:"+item.getString("title")); // System.out.println("node_token:"+item.getString("node_token")); getListSpaceNode(spaceId, item.getString("node_token"), path+"/"+item.getString("title"),""); }else { try { // Files.createDirectories(Paths.get(path));// 创建目录 File dir = new File(path); if(!dir.exists()) { System.out.println("创建目录:"+path); dir.mkdirs(); } // System.out.println(path+"/"+item.getString("title")); String title = item.getString("title"); File file = new File(path+"/"+title); // if(title.contains(".") && !Files.exists(Paths.get(path,title))) { // if("file".equals(item.getString("obj_type")) && !Files.exists(Paths.get(path,title))) { if("file".equals(item.getString("obj_type")) && !file.exists()) { System.out.println("下载:"+title); downloadFile(item.getString("obj_token"), path+"/"+title); // 下载 } } catch (Exception e) { e.printStackTrace(); } } } if(data.getBoolean("has_more")) { getListSpaceNode(spaceId, parentNodeToken, path, data.getString("page_token")); } } /** * 2.下载文件 * 2025年12月17日 上午11:14:01 @author jangle * @param objToken 文件token * @param filepath 文件下载路径 */ private void downloadFile(String objToken,String filepath) { for(int i=0;i<3;i++) { try { // 创建请求对象 DownloadFileReq req = DownloadFileReq.newBuilder() .fileToken(objToken) .build(); // 发起请求 DownloadFileResp resp = client.drive().v1().file().download(req); // 处理服务端错误 if (!resp.success()) { System.out.println(String.format("code:%s,msg:%s,reqId:%s, resp:%s", resp.getCode(), resp.getMsg(), resp.getRequestId(), Jsons.createGSON(true, false).toJson(JsonParser.parseString(new String(resp.getRawResponse().getBody(), StandardCharsets.UTF_8))))); return; } // 业务数据处理 resp.writeFile(filepath); return; } catch(Exception e) { e.printStackTrace(); try { TimeUnit.SECONDS.sleep(1 * (i + 1)); } catch (InterruptedException ie) { ie.printStackTrace(); Thread.currentThread().interrupt(); return; } } } } /** * 0.主程序入口 * 2025年12月17日 上午10:38:34 @author jangle * @param args */ public static void main(String[] args) { FeishuZSKMain main = new FeishuZSKMain(); try { main.getListSpaceNode("732***********14146", "", "D:/filepath",""); } catch (Exception e) { e.printStackTrace(); } } }
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/3/10 14:15:15

网页数学公式编辑的革命性解决方案:MathLive 全面指南

网页数学公式编辑的革命性解决方案&#xff1a;MathLive 全面指南 【免费下载链接】mathlive A web component for easy math input 项目地址: https://gitcode.com/gh_mirrors/ma/mathlive 在当今数字化教育和技术文档领域&#xff0c;数学公式的在线编辑一直是个技术难…

作者头像 李华
网站建设 2026/3/10 6:54:07

如何让AI学会打游戏?深度拆解3个顶级游戏Agent训练案例

第一章&#xff1a;游戏AI的发展与挑战游戏人工智能&#xff08;Game AI&#xff09;作为计算机科学与娱乐产业交汇的重要领域&#xff0c;近年来经历了从规则驱动到学习驱动的深刻变革。早期的游戏AI主要依赖预设的行为树或状态机&#xff0c;例如在《吃豆人》中&#xff0c;每…

作者头像 李华
网站建设 2026/3/4 2:31:21

茈碧湖:不止是洱海之源,更有 “水花树” 奇观

在云南大理的苍山云弄峰下&#xff0c;有一片被群山温柔环抱的湖泊。它不如洱海那般声名远扬&#xff0c;却以一抹澄澈的碧色和湖中独有的花朵&#xff0c;静默地诠释着“源头”二字的清幽与纯粹。这里便是洱海之源——茈碧湖。茈碧湖的湖水清澈&#xff0c;色碧如玉。无论是春…

作者头像 李华
网站建设 2026/3/10 14:30:35

python-flask-django火车票购票系统_33bx0nk0

文章目录 系统截图项目技术简介可行性分析主要运用技术介绍核心代码参考示例结论源码lw获取/同行可拿货,招校园代理 &#xff1a;文章底部获取博主联系方式&#xff01; 系统截图 篇樱桃红-flas卡-django_co3bxnk 火车票购票系统 项目技术简介 Python版本&#xff1a;py…

作者头像 李华
网站建设 2026/3/4 1:59:22

python-flask-django简历智能推荐系统_jw8dzu00

文章目录系统截图项目技术简介可行性分析主要运用技术介绍核心代码参考示例结论源码lw获取/同行可拿货,招校园代理 &#xff1a;文章底部获取博主联系方式&#xff01;系统截图 python-flask-django_jw8dzu00 简历智能推荐系统 项目技术简介 Python版本&#xff1a;pytho…

作者头像 李华