简介
Maton官方提供的OneDrive API集成方案,通过托管OAuth网关实现文件全生命周期管理,让开发者无需自建认证即可调用Microsoft Graph API。
原始描述
MS OneDrive integration. Manage Accounts. Use when the user wants to interact with MS OneDrive data.
中文使用说明 来自收录源
核心用法
OneDrive Skill 是一个纯文档型 API 集成工具,通过 Maton 网关代理调用 Microsoft Graph API,实现 OneDrive 云存储的完整管理。用户需先在 maton.ai 平台获取 MATON_API_KEY 环境变量,并通过 OAuth 流程完成 Microsoft 账号授权。
主要功能覆盖四大场景:
- 文件管理:列出/搜索文件、创建文件夹、上传下载(支持4MB以下简单上传和大文件分片续传)、重命名移动删除
- 驱动器操作:获取个人存储空间信息、查看配额使用状况、访问特殊文件夹(文档/照片/音乐)
- 分享协作:生成匿名或组织内分享链接(只读/可编辑)、向指定用户发送邀请邮件
- 连接管理:通过 REST API 创建/查看/删除 OAuth 连接,支持多账户切换
所有 API 调用均需 Authorization: Bearer $MATON_API_KEY 头部认证,多连接场景可通过 Maton-Connection 头部指定特定连接。
显著优点
- 零代码入侵:纯 Markdown 文档型 Skill,无实际可执行代码,用户完全掌控请求逻辑
- 托管OAuth简化流程:Maton 平台集中处理 Microsoft OAuth 令牌刷新,无需自行实现复杂的 OAuth 2.0 流程
- 企业级API背书:底层调用 Microsoft Graph API,数据安全性和服务可靠性由微软保障
- 完整功能覆盖:从基础文件操作到高级分享权限管理,提供 OneDrive 全能力接口
- 多语言示例丰富:Bash/Python/JavaScript 代码片段齐全,降低接入门槛
潜在局限
- 第三方网关依赖:所有请求必须经 gateway.maton.ai 代理,服务可用性受 Maton 平台影响
- 商业许可成本:Maton API Key 和 OAuth 连接可能涉及付费,文档未明确说明免费额度
- 大文件上传复杂:超过4MB需实现分片续传,文档示例较简略,生产环境需额外开发
- 下载URL临时性:
@microsoft.graph.downloadUrl为短期预认证链接,需及时消费 - 调试门槛:错误处理涉及多层(Maton网关+Microsoft Graph),问题定位需排查两个服务
适合人群
- 需要将 OneDrive 集成到自动化工作流的开发者
- 寻求托管 OAuth 方案、不愿自建认证服务的团队
- 已使用 Microsoft 365 生态的企业用户
- 熟悉 REST API 调用、具备环境变量配置基础的技术人员
常规风险
| 风险类型 | 说明 | 缓解建议 |
|---|---|---|
| API密钥泄露 | MATON_API_KEY 泄露可能导致 OneDrive 数据被非法访问 |
配置在 .bashrc/.zshrc,避免命令行直接输入;定期轮换密钥 |
| 误操作数据丢失 | 删除操作不可逆,分享链接可能被意外公开 | 操作前验证路径;使用 rename 冲突策略;分享采用 organization 范围 |
| OAuth令牌过期 | 连接长期未用可能失效 | 通过 ctrl.maton.ai 定期审查连接状态 |
| 服务依赖中断 | Maton 或 Microsoft 服务故障导致功能不可用 | 关键业务实现本地缓存和重试机制 |
| 数据跨境传输 | 文件经美国微软服务处理,需符合数据合规要求 | 敏感数据评估后再上传,考虑合规替代方案 |
技能正文
name: onedrive description: | OneDrive API integration with managed OAuth via Microsoft Graph. Manage files, folders, and sharing. Use this skill when users want to upload, download, organize, or share files in OneDrive. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway). Requires network access and valid Maton API key. metadata: author: maton version: "1.0" clawdbot: emoji: 🧠 requires: env: - MATON_API_KEY
OneDrive
Access the OneDrive API with managed OAuth authentication via Microsoft Graph. Manage files, folders, drives, and sharing with full CRUD operations.
Quick Start
# List files in OneDrive root
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://gateway.maton.ai/one-drive/v1.0/me/drive/root/children')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
Base URL
https://gateway.maton.ai/one-drive/v1.0/{resource}
The gateway proxies requests to graph.microsoft.com and automatically injects your OAuth token.
Authentication
All requests require the Maton API key in the Authorization header:
Authorization: Bearer $MATON_API_KEY
Environment Variable: Set your API key as MATON_API_KEY:
export MATON_API_KEY="YOUR_API_KEY"
Getting Your API Key
- Sign in or create an account at maton.ai
- Go to maton.ai/settings
- Copy your API key
Connection Management
Manage your OneDrive OAuth connections at https://ctrl.maton.ai.
List Connections
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections?app=one-drive&status=ACTIVE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
Create Connection
python <<'EOF'
import urllib.request, os, json
data = json.dumps({'app': 'one-drive'}).encode()
req = urllib.request.Request('https://ctrl.maton.ai/connections', data=data, method='POST')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Content-Type', 'application/json')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
Get Connection
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections/{connection_id}')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
Response:
{
"connection": {
"connection_id": "3f17fb58-4515-4840-8ef6-2bbf0fa67e2c",
"status": "ACTIVE",
"creation_time": "2026-02-07T08:23:30.317909Z",
"last_updated_time": "2026-02-07T08:24:04.925298Z",
"url": "https://connect.maton.ai/?session_token=...",
"app": "one-drive",
"metadata": {}
}
}
Open the returned url in a browser to complete OAuth authorization.
Delete Connection
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections/{connection_id}', method='DELETE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
Specifying Connection
If you have multiple OneDrive connections, specify which one to use with the Maton-Connection header:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://gateway.maton.ai/one-drive/v1.0/me/drive')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Maton-Connection', '3f17fb58-4515-4840-8ef6-2bbf0fa67e2c')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
If omitted, the gateway uses the default (oldest) active connection.
API Reference
Drives
Get Current User's Drive
GET /one-drive/v1.0/me/drive
Response:
{
"id": "b!F3Y7M0VT80OO9iu_D6Z-LA...",
"driveType": "personal",
"name": "OneDrive",
"owner": {
"user": {
"displayName": "John Doe",
"id": "d4648f06c91d9d3d"
}
},
"quota": {
"total": 5368709120,
"used": 1234567,
"remaining": 5367474553
}
}
List User's Drives
GET /one-drive/v1.0/me/drives
Get Drive by ID
GET /one-drive/v1.0/drives/{drive-id}
Files and Folders
Get Drive Root
GET /one-drive/v1.0/me/drive/root
List Root Children
GET /one-drive/v1.0/me/drive/root/children
Response:
{
"value": [
{
"id": "F33B7653325337C3!s88...",
"name": "Documents",
"folder": {
"childCount": 5
},
"createdDateTime": "2024-01-15T10:30:00Z",
"lastModifiedDateTime": "2024-02-01T14:20:00Z"
},
{
"id": "F33B7653325337C3!s3f...",
"name": "report.pdf",
"file": {
"mimeType": "application/pdf",
"hashes": {
"sha1Hash": "cf23df2207d99a74fbe169e3eba035e633b65d94"
}
},
"size": 35212
}
]
}
Get Item by ID
GET /one-drive/v1.0/me/drive/items/{item-id}
Get Item by Path
Use colon (:) syntax to access items by path:
GET /one-drive/v1.0/me/drive/root:/Documents/report.pdf
List Folder Children by Path
GET /one-drive/v1.0/me/drive/root:/Documents:/children
Get Item Children
GET /one-drive/v1.0/me/drive/items/{item-id}/children
Special Folders
Access known folders by name:
GET /one-drive/v1.0/me/drive/special/documents
GET /one-drive/v1.0/me/drive/special/photos
GET /one-drive/v1.0/me/drive/special/music
GET /one-drive/v1.0/me/drive/special/approot
Recent and Shared
Get Recent Files
GET /one-drive/v1.0/me/drive/recent
Get Files Shared With Me
GET /one-drive/v1.0/me/drive/sharedWithMe
Search
GET /one-drive/v1.0/me/drive/root/search(q='{query}')
Example:
GET /one-drive/v1.0/me/drive/root/search(q='budget')
Create Folder
POST /one-drive/v1.0/me/drive/root/children
Content-Type: application/json
{
"name": "New Folder",
"folder": {},
"@microsoft.graph.conflictBehavior": "rename"
}
Create folder inside another folder:
POST /one-drive/v1.0/me/drive/items/{parent-id}/children
Content-Type: application/json
{
"name": "Subfolder",
"folder": {}
}
Upload File (Simple - up to 4MB)
PUT /one-drive/v1.0/me/drive/items/{parent-id}:/{filename}:/content
Content-Type: application/octet-stream
{file binary content}
Example - upload to root:
PUT /one-drive/v1.0/me/drive/root:/document.txt:/content
Content-Type: text/plain
Hello, OneDrive!
Upload File (Large - resumable)
For files over 4MB, use resumable upload:
Step 1: Create upload session
POST /one-drive/v1.0/me/drive/root:/{filename}:/createUploadSession
Content-Type: application/json
{
"item": {
"@microsoft.graph.conflictBehavior": "rename"
}
}
Response:
{
"uploadUrl": "https://sn3302.up.1drv.com/up/...",
"expirationDateTime": "2024-02-08T10:00:00Z"
}
Step 2: Upload bytes to the uploadUrl
Download File
Get the file metadata to retrieve the download URL:
GET /one-drive/v1.0/me/drive/items/{item-id}
The response includes @microsoft.graph.downloadUrl - a pre-authenticated URL valid for a short time:
{
"id": "...",
"name": "document.pdf",
"@microsoft.graph.downloadUrl": "https://public-sn3302.files.1drv.com/..."
}
Use this URL directly to download the file content (no auth header needed).
Update Item (Rename/Move)
PATCH /one-drive/v1.0/me/drive/items/{item-id}
Content-Type: application/json
{
"name": "new-name.txt"
}
Move to different folder:
PATCH /one-drive/v1.0/me/drive/items/{item-id}
Content-Type: application/json
{
"parentReference": {
"id": "{new-parent-id}"
}
}
Copy Item
POST /one-drive/v1.0/me/drive/items/{item-id}/copy
Content-Type: application/json
{
"parentReference": {
"id": "{destination-folder-id}"
},
"name": "copied-file.txt"
}
Returns 202 Accepted with a Location header to monitor the copy operation.
Delete Item
DELETE /one-drive/v1.0/me/drive/items/{item-id}
Returns 204 No Content on success.
Sharing
Create Sharing Link
POST /one-drive/v1.0/me/drive/items/{item-id}/createLink
Content-Type: application/json
{
"type": "view",
"scope": "anonymous"
}
Link types:
view- Read-only accessedit- Read-write accessembed- Embeddable link
Scopes:
anonymous- Anyone with the linkorganization- Anyone in your organization
Response:
{
"id": "...",
"link": {
"type": "view",
"scope": "anonymous",
"webUrl": "https://1drv.ms/b/..."
}
}
Invite Users (Share with specific people)
POST /one-drive/v1.0/me/drive/items/{item-id}/invite
Content-Type: application/json
{
"recipients": [
{"email": "user@example.com"}
],
"roles": ["read"],
"sendInvitation": true,
"message": "Check out this file!"
}
Query Parameters
Customize responses with OData query parameters:
$select- Choose specific properties:?$select=id,name,size$expand- Include related resources:?$expand=children$filter- Filter results:?$filter=file ne null(files only)$orderby- Sort results:?$orderby=name$top- Limit results:?$top=10
Example:
GET /one-drive/v1.0/me/drive/root/children?$select=id,name,size&$top=20&$orderby=name
Pagination
Results are paginated. The response includes @odata.nextLink for additional pages:
{
"value": [...],
"@odata.nextLink": "https://graph.microsoft.com/v1.0/me/drive/root/children?$skiptoken=..."
}
Use the full URL from @odata.nextLink (without the gateway prefix) to fetch the next page.
Code Examples
JavaScript
// List files in root
const response = await fetch(
'https://gateway.maton.ai/one-drive/v1.0/me/drive/root/children',
{
headers: {
'Authorization': `Bearer ${process.env.MATON_API_KEY}`
}
}
);
const data = await response.json();
// Upload a file
const uploadResponse = await fetch(
'https://gateway.maton.ai/one-drive/v1.0/me/drive/root:/myfile.txt:/content',
{
method: 'PUT',
headers: {
'Authorization': `Bearer ${process.env.MATON_API_KEY}`,
'Content-Type': 'text/plain'
},
body: 'Hello, OneDrive!'
}
);
Python
import os
import requests
# List files in root
response = requests.get(
'https://gateway.maton.ai/one-drive/v1.0/me/drive/root/children',
headers={'Authorization': f'Bearer {os.environ["MATON_API_KEY"]}'}
)
files = response.json()
# Upload a file
upload_response = requests.put(
'https://gateway.maton.ai/one-drive/v1.0/me/drive/root:/myfile.txt:/content',
headers={
'Authorization': f'Bearer {os.environ["MATON_API_KEY"]}',
'Content-Type': 'text/plain'
},
data='Hello, OneDrive!'
)
Notes
- OneDrive uses Microsoft Graph API (
graph.microsoft.com) - Item IDs are unique within a drive
- Use colon (
:) syntax for path-based addressing:/root:/path/to/file - Simple uploads are limited to 4MB; use resumable upload for larger files
- Download URLs from
@microsoft.graph.downloadUrlare pre-authenticated and temporary - Conflict behavior options:
fail,replace,rename - IMPORTANT: When using curl commands, use
curl -gwhen URLs contain brackets to disable glob parsing - IMPORTANT: When piping curl output to
jqor other commands, environment variables like$MATON_API_KEYmay not expand correctly in some shell environments
Error Handling
| Status | Meaning |
|---|---|
| 400 | Missing OneDrive connection or invalid request |
| 401 | Invalid or missing Maton API key |
| 403 | Insufficient permissions |
| 404 | Item not found |
| 409 | Conflict (e.g., item already exists) |
| 429 | Rate limited (check Retry-After header) |
| 4xx/5xx | Passthrough error from Microsoft Graph API |
Error Response Format
{
"error": {
"code": "itemNotFound",
"message": "The resource could not be found."
}
}
Troubleshooting: API Key Issues
- Check that the
MATON_API_KEYenvironment variable is set:
echo $MATON_API_KEY
- Verify the API key is valid by listing connections:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
Troubleshooting: Invalid App Name
- Ensure your URL path starts with
one-drive. For example:
- Correct:
https://gateway.maton.ai/one-drive/v1.0/me/drive/root/children - Incorrect:
https://gateway.maton.ai/v1.0/me/drive/root/children
Resources
- OneDrive Developer Documentation
- Microsoft Graph API Reference
- DriveItem Resource
- Drive Resource
- Sharing and Permissions
- Large File Upload
- Maton Community
- Maton Support
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。