|
通过托管OAuth认证访问Google Drive API。列出、搜索、创建和管理文件与文件夹。
bash
https://gateway.maton.ai/google-drive/{原生API路径}
将{原生API路径}替换为实际的Google Drive API端点路径。网关将请求代理到www.googleapis.com,并自动注入您的OAuth令牌。
所有请求都需要在Authorization头中包含Maton API密钥:
Authorization: Bearer $MATONAPIKEY
环境变量: 将您的API密钥设置为MATONAPIKEY:
bash
export MATONAPIKEY=您的API密钥
在https://ctrl.maton.ai管理您的Google OAuth连接。
bash
python <
req = urllib.request.Request(https://ctrl.maton.ai/connections?app=google-drive&status=ACTIVE)
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
bash
python <
data = json.dumps({app: google-drive}).encode()
req = urllib.request.Request(https://ctrl.maton.ai/connections, data=data, method=POST)
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
req.add_header(Content-Type, application/json)
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
bash
python <
req = urllib.request.Request(https://ctrl.maton.ai/connections/{connection_id})
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
响应:
json
{
connection: {
connection_id: 21fd90f9-5935-43cd-b6c8-bde9d915ca80,
status: ACTIVE,
creation_time: 2025-12-08T07:20:53.488460Z,
lastupdatedtime: 2026-01-31T20:03:32.593153Z,
url: https://connect.maton.ai/?session_token=...,
app: google-drive,
metadata: {}
}
}
在浏览器中打开返回的url以完成OAuth授权。
bash
python <
req = urllib.request.Request(https://ctrl.maton.ai/connections/{connection_id}, method=DELETE)
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
如果您有多个Google Drive连接,请使用Maton-Connection头指定要使用的连接:
bash
python <
req = urllib.request.Request(https://gateway.maton.ai/google-drive/drive/v3/files?pageSize=10)
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
req.add_header(Maton-Connection, 21fd90f9-5935-43cd-b6c8-bde9d915ca80)
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
如果省略,网关将使用默认(最早)的活动连接。
bash
GET /google-drive/drive/v3/files?pageSize=10
带查询条件:
bash
GET /google-drive/drive/v3/files?q=name%20contains%20report&pageSize=10
仅文件夹:
bash
GET /google-drive/drive/v3/files?q=mimeType=application/vnd.google-apps.folder
特定文件夹中的文件:
bash
GET /google-drive/drive/v3/files?q=FOLDER_ID+in+parents
带字段选择:
bash
GET /google-drive/drive/v3/files?fields=files(id,name,mimeType,createdTime,modifiedTime,size)
bash
GET /google-drive/drive/v3/files/{fileId}?fields=id,name,mimeType,size,createdTime
bash
GET /google-drive/drive/v3/files/{fileId}?alt=media
bash
GET /google-drive/drive/v3/files/{fileId}/export?mimeType=application/pdf
bash
POST /google-drive/drive/v3/files
Content-Type: application/json
{
name: 新文档,
mimeType: application/vnd.google-apps.document
}
bash
POST /google-drive/drive/v3/files
Content-Type: application/json
{
name: 新文件夹,
mimeType: application/vnd.google-apps.folder
}
bash
PATCH /google-drive/drive/v3/files/{fileId}
Content-Type: application/json
{
name: 重命名的文件
}
bash
PATCH /google-drive/drive/v3/files/{fileId}?addParents=NEWFOLDERID&removeParents=OLDFOLDERID
bash
DELETE /google-drive/drive/v3/files/{fileId}
bash
POST /google-drive/drive/v3/files/{fileId}/copy
Content-Type: application/json
{
name: 文件的副本
}
Google Drive支持三种上传类型,取决于文件大小以及是否需要包含元数据。
适用于不超过5MB且无需设置元数据的文件。
bash
POST /google-drive/upload/drive/v3/files?uploadType=media
Content-Type: text/plain
<文件内容>
Python示例:
python
import urllib.request, os
file_content = b你好,这是文件内容!
url = https://gateway.maton.ai/google-drive/upload/drive/v3/files?uploadType=media
req = urllib.request.Request(url, data=file_content, method=POST)
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
req.add_header(Content-Type, text/plain)
response = urllib.request.urlopen(req)
适用于不超过5MB且需要包含元数据(名称、描述等)的文件。
bash
POST /google-drive/upload/drive/v3/files?uploadType=multipart
Content-Type: multipart/related; boundary=boundary
--boundary
Content-Type: application/json; charset=UTF-8
{name: myfile.txt, description: 我的文件}
--boundary
Content-Type: text/plain
<文件内容>
--boundary--
Python示例:
python
import urllib.request, os, json
boundary = ----Boundary
metadata = json.dumps({name: myfile.txt, description: 我的文件})
file_content = 文件内容在这里
body = f--{boundary}\r
Content-Type: application/json; charset=UTF-8\r
\r
{metadata}\r
--{boundary}\r
Content-Type: text/plain\r
\r
{file_content}\r
--{boundary}--.encode()
url = https://gateway.maton.ai/google-drive/upload/drive/v3/files?uploadType=multipart
req = urllib.request.Request(url, data=body, method=POST)
req.addheader(Authorization, fBearer {os.environ[MATONAPI_KEY]})
req.add_header(Content-Type, fmultipart/related; boundary={bound
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 google-drive-1776371423 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 google-drive-1776371423 技能
skillhub install google-drive-1776371423
文件大小: 5.52 KB | 发布时间: 2026-4-17 15:29