news 2026/6/17 18:40:04

飞书知识库备份

作者头像

张小明

前端开发工程师

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/6/16 14:15:44

中国辅助驾驶“新竞赛”打响,高智价比AI芯片如何定义新标杆?

中国辅助驾驶的落地竞速已经从单纯的性能比拼&#xff0c;进入“法规与体验双轮驱动”的全新阶段。一方面&#xff0c;包括中国在内的全球多个国家和地区已对车辆搭载AEB系统提出强制性要求&#xff0c;直接推动了组合辅助驾驶进入市场主导的“爆发期”。根据《高工智能汽车研究…

作者头像 李华
网站建设 2026/6/17 2:00:10

渔人的直感:FF14终极智能钓鱼计时器完全指南

渔人的直感&#xff1a;FF14终极智能钓鱼计时器完全指南 【免费下载链接】Fishers-Intuition 渔人的直感&#xff0c;最终幻想14钓鱼计时器 项目地址: https://gitcode.com/gh_mirrors/fi/Fishers-Intuition 还在为错过幻海流最佳时机而烦恼吗&#xff1f;是否经常因为分…

作者头像 李华
网站建设 2026/6/13 11:02:53

如何在30天内完成Agent有效性验证?生物药研发加速的秘密武器

第一章&#xff1a;生物制药Agent有效性验证的挑战与机遇在生物制药领域&#xff0c;智能Agent正逐步应用于药物发现、靶点识别和临床试验模拟等关键环节。然而&#xff0c;这些Agent的有效性验证面临诸多挑战&#xff0c;同时也孕育着重大技术突破的机遇。数据异质性与标准化难…

作者头像 李华
网站建设 2026/6/12 9:50:38

为什么顶尖金融机构都在重构Agent审计日志?背后隐藏的4大合规趋势

第一章&#xff1a;金融合规 Agent 的审计日志在金融行业&#xff0c;系统操作的可追溯性是合规性的核心要求之一。审计日志作为记录系统行为的关键组件&#xff0c;为监管审查、异常检测和责任追溯提供了数据基础。金融合规 Agent 通过自动化手段收集、分析并归档关键操作事件…

作者头像 李华
网站建设 2026/6/13 18:21:28

58、Linux与Ubuntu:深入解析与使用指南

Linux与Ubuntu:深入解析与使用指南 1. mkinitrd工具介绍 mkinitrd工具会查看 /etc/fstab 、 /etc/modprobe.conf 和 /etc/raidtab 文件,以获取在启动过程中确定需要加载哪些模块所需的信息。在我们的系统中,使用以下命令: # mkinitrd initrd-2.6.7-1.img 2.6.7-1…

作者头像 李华
网站建设 2026/6/11 21:39:19

60、Ubuntu安装规划与硬件要求全解析

Ubuntu安装规划与硬件要求全解析 1. 选择Ubuntu的优势与安装关键因素 Ubuntu作为一种计算解决方案有诸多优势,由于其丰富的软件资源,它能在不同层级和硬件平台上扮演多种角色。为确保安装成功,需关注以下关键因素: - 准备工作 :充分讨论迁移或部署事宜,明确其带来的…

作者头像 李华