{"id":19273072,"url":"https://github.com/fluttercandies/baidupan","last_synced_at":"2026-01-11T04:45:06.230Z","repository":{"id":40415472,"uuid":"465658603","full_name":"fluttercandies/baidupan","owner":"fluttercandies","description":"Baidu net disk api for dart, 百度网盘的 dart 库","archived":false,"fork":false,"pushed_at":"2024-06-24T09:17:49.000Z","size":136,"stargazers_count":26,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-24T10:42:01.423Z","etag":null,"topics":["baidu-pan","dart","flutter","sdk"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fluttercandies.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-03T09:49:09.000Z","updated_at":"2024-06-24T09:17:52.000Z","dependencies_parsed_at":"2023-11-21T06:25:01.824Z","dependency_job_id":"d48368c7-031c-49f5-9709-7bfb9bbe7237","html_url":"https://github.com/fluttercandies/baidupan","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluttercandies%2Fbaidupan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluttercandies%2Fbaidupan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluttercandies%2Fbaidupan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluttercandies%2Fbaidupan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fluttercandies","download_url":"https://codeload.github.com/fluttercandies/baidupan/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223881803,"owners_count":17219268,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["baidu-pan","dart","flutter","sdk"],"created_at":"2024-11-09T20:40:43.368Z","updated_at":"2026-01-11T04:45:06.192Z","avatar_url":"https://github.com/fluttercandies.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BaiduPan\n\n百度网盘的 API, 可以帮助在 dart 中对接百度网盘\n\n目前理论上不支持 **web**， 因为引入了 dart:io 包\n\n有一些未对接的接口可以查看 [官方文档](https://pan.baidu.com/union/doc/nksg0sbfs)\n\n## API 的配置\n\n到 [百度开放平台的应用列表](https://pan.baidu.com/union/console/applist) 中获取\n\n这里主要需要的的是 AppKey 和 AppSecret\n\n## 授权码\n\n\u003e 写在前面：这里要注意一点，非常重要，请仔细阅读后再继续！！！！\n\n\u003e 写在前面：这里要注意一点，非常重要，请仔细阅读后再继续！！！！\n\n\u003e 写在前面：这里要注意一点，非常重要，请仔细阅读后再继续！！！！\n\n**不要**把 code 或 access_token 暴露给**任何人**，因为有了这个东西，别人就能**访问**你的百度网盘了，甚至可以**删除你所有数据**\n\n### 授权码的概念\n\n这里有一个 `code` 和 `access_token` 的概念, `code` 为登录用户给予的授权码, 需要使用 `code` 换取 `access_token`\n\ncode 10 分钟过期, 暂时是手动填入, 当然你可以自己寻求自动化的进程, 或者如果你有服务器端, 也可以使用服务端授权模式，这和本 SDK 无关\n\n获取到 accessToken 后保存下来，下次需要时直接使用即可， 这个 accessToken 的有效期为 30 天，可以使用 `refresh_token` 刷新， 但是我这里没做刷新的相关逻辑，有需要的时候请重新获取\naccessToken\n\n### 使用代码简化步骤\n\n`BaiduAuthManager` 可以简化这个过程\n\n```dart\n\nvoid main() async {\n  final authManager = BaiduAuthManager(appId, appSecret);\n  final uri = authManager.getAuthUrl();\n  print(uri); // 这里使用浏览器访问这个 url ，然后复制 code,\n\n  final auth = await authManager.requestAccessToken(code);\n  print(auth.accessToken); // 这里就是 accessToken， 其他字段的含义请参考官方文档\n}\n```\n\n## 使用说明\n\n因为百度网盘的 API 有一些坑，这里进行了一些封装，然后使用 3 个核心类来对应不同的功能\n\n具体功能参照官方的说明文档\n\n入口类有 3 个，分别对应查询，操作，上传\n\n- `BaiduPan`: 对应百度网盘的核心 API，主要是获取信息\n  - `getUserInfo`: 获取用户信息\n  - `getDiskSpace`: 获取网盘空间信息\n  - `getFileList`: 获取文件列表\n  - `getFileListAll`: 递归获取文件列表\n  - `getDocList`: 获取文档列表\n  - `getImageList`: 获取图片列表\n  - `getVideoList`: 获取视频列表\n  - `getBtList`: 获取 BT 列表\n  - `getCountOfPathByType`: 获取某个目录下的文件类型数量\n  - `getCategoryList`: 获取网盘分类列表\n  - `search`: 搜索\n  - `getMetaData`: 获取文件元数据\n  - `getDownloadRequest`: 获取下载请求\n  - `getDownloadUrl`: 获取下载地址\n- `BaiduPanFileManager`: 操作文件的管理类\n  - `copy`: 复制文件\n  - `move`: 移动文件\n  - `rename`: 重命名文件\n  - `delete`: 删除文件\n  - `createFolder`: 创建文件夹\n- `BaiduPanUploadManager`: 上传文件的管理类\n  - `preCreate`: 预创建文件\n  - `uploadSinglePart`: 上传分片文件\n  - `merge`: 合并分片（上传完成）\n\n## 上传文件的断点续传问题\n\n如果文件过大或网络不稳定，可能会中断，这里封装了一个类可以帮助解决这个问题\n\n`BaiduUploadHelper`\n\n### 运行在内存中\n\n这种情况适用于程序未关闭的情况下，比如 app 或服务器端程序\n\n只需要重新调用同一个对象的`startUpload`即可\n\n原理是对象内保存了下载的 md5 列表和 uploadId, 这样可以自动续传\n\n### 运行在命令行中\n\n因为每次可能都要开启一个新的程序来上传，这时需要将断点信息保存至文件内，在下次加载时传入对象内\n\n使用 `saveProgressToFile` 来保存进度信息到 file\n\n使用 `BaiduUploadHelper.resumeFromFile` 来从文件恢复\n\n## 命令行工具\n\n项目提供了一个简单的上传工具，需要配合 [pub global][] 使用\n\n使用前需要配置文件或环境变量以访问 access_token，\n\n### 安装\n\n```zsh\ndart pub global activate baidupan\n```\n\n### 使用配置文件\n\n配置文件的方式：生成一个 `config.json` 文件，`$HOME/.config/baidupan/config.json`，这个文件的格式如下\n\n```json\n{\n  \"expires_in\": 2592000,\n  \"refresh_token\": \"\",\n  \"access_token\": \"\",\n  \"session_secret\": \"\",\n  \"session_key\": \"\",\n  \"scope\": \"basic netdisk\"\n}\n```\n\n这个文件可以使用 `requset_baidu_auth` 工具生成\n\n```sh\nexport baidu_app_id=xxx\nexport baidu_app_secret=xxx\n\n# 如果你已经获取了 code，请设置环境变量\nexport baidu_request_code=xxx\n\ndart run bin/request_baidu_auth.dart\n\nor\n\nrequest_baidu_auth\n```\n\n### 环境变量\n\n还可以通过环境变量设置 access_token\n\n```sh\nexport BAIDU_PAN_ACCESS_TOKEN=xxx\n```\n\n### 上传文件\n\n```shell\n\n# 上传\nbd_upload \u003clocal_path\u003e \u003cremote_path\u003e\n```\n\n## LICENSE\n\nApache 2.0\n\n[pub global]: https://dart.cn/tools/pub/cmd/pub-global\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluttercandies%2Fbaidupan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffluttercandies%2Fbaidupan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluttercandies%2Fbaidupan/lists"}