news 2026/7/7 11:52:22

飞书知识库备份

作者头像

张小明

前端开发工程师

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/7/7 18:49:24

IINA:重新定义macOS视频播放体验的革命性工具

IINA&#xff1a;重新定义macOS视频播放体验的革命性工具 【免费下载链接】iina 项目地址: https://gitcode.com/gh_mirrors/iin/iina 还在为macOS平台寻找一款真正专业的视频播放器而困扰吗&#xff1f;IINA的出现彻底改变了这一现状。这款基于mpv引擎深度优化的开源播…

作者头像 李华
网站建设 2026/7/7 14:10:27

macOS屏幕录制新纪元:QuickRecorder专业配置手册

macOS屏幕录制新纪元&#xff1a;QuickRecorder专业配置手册 【免费下载链接】QuickRecorder A lightweight screen recorder based on ScreenCapture Kit for macOS / 基于 ScreenCapture Kit 的轻量化多功能 macOS 录屏工具 项目地址: https://gitcode.com/GitHub_Trending…

作者头像 李华
网站建设 2026/7/7 11:10:22

C++贪心———区间覆盖区间调度

一、什么是区间覆盖问题 “给你很多区间&#xff0c;让你用最少个数&#xff0c;覆盖一个目标区间” 二、区间覆盖贪心核心思想 按照左端点升序排序&#xff0c;当前要覆盖到 pos&#xff0c;在所有 L ≤ pos 的区间中&#xff0c;选择 r 最大的那个。 三、区间覆盖核心代码…

作者头像 李华
网站建设 2026/7/7 11:57:58

(工业控制Agent容错技术白皮书):从理论到落地的完整工程实践路径

第一章&#xff1a;工业控制Agent容错机制概述 在现代工业自动化系统中&#xff0c;控制Agent作为核心执行单元&#xff0c;承担着数据采集、逻辑判断与实时控制等关键任务。由于工业环境复杂多变&#xff0c;硬件故障、网络延迟、软件异常等因素可能导致Agent失效&#xff0c;…

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

ImageToSTL终极指南:快速将图片转换为3D打印模型

ImageToSTL终极指南&#xff1a;快速将图片转换为3D打印模型 【免费下载链接】ImageToSTL This tool allows you to easily convert any image into a 3D print-ready STL model. The surface of the model will display the image when illuminated from the left side. 项目…

作者头像 李华
网站建设 2026/7/7 11:48:14

基于微信小程序的陕西地区特色农产品团购平台

Spring Boot基于微信小程序的陕西地区特色农产品团购平台是一个集成了现代化信息技术与农产品销售的创新性平台。以下是对该平台的详细介绍&#xff1a; 一、平台背景与目的 该平台旨在利用Spring Boot框架的高效性和微信小程序的便捷性&#xff0c;为陕西地区的特色农产品提供…

作者头像 李华