与云端硬盘界面的“新建”按钮集成
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
当用户点击 Google 云端硬盘界面中的“新建”按钮并在 Google 云端硬盘界面中选择某个应用时,Google 云端硬盘会将用户重定向到该应用在配置 Google 云端硬盘界面集成中定义的新建网址。
然后,您的应用会在 state
参数中收到一组默认的模板变量。新网址的默认 state
信息为:
{
"action":"create",
"folderId":"FOLDER_ID",
"folderResourceKey":"FOLDER_RESOURCE_KEY",
"userId":"USER_ID"
}
此输出包括以下值:
create
:正在执行的操作。当用户点击 Google 云端硬盘界面的“新建”按钮时,该值为 create
。
- FOLDER_ID:父文件夹的 ID。
- FOLDER_RESOURCE_KEY:父文件夹的资源键。
- USER_ID:唯一标识用户的个人资料 ID。
您的应用必须按照以下步骤对该请求采取行动:
- 验证
action
字段的值是否为 create
。
- 使用
userId
值为用户创建新会话。如需详细了解已登录用户,请参阅用户和新事件。
- 使用
files.create
方法创建文件资源。如果请求中设置了 folderId
,请将 parents
字段设置为 folderId
值。
- 如果请求中设置了
folderResourceKey
,则设置 X-Goog-Drive-Resource-Keys
请求标头。如需详细了解资源密钥,请参阅使用资源密钥访问通过链接共享的文件。
state
参数经过网址编码,因此您的应用必须处理转义字符并将其解析为 JSON。
用户和新事件
Google 云端硬盘应用应将所有“创建”事件视为潜在的登录事件。部分用户可能拥有多个账号,因此 state
参数中的用户 ID 可能与当前会话不匹配。如果 state
参数中的用户 ID 与当前会话不匹配,请结束应用的当前会话,并以所请求的用户身份登录。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-04。
[null,null,["最后更新时间 (UTC):2025-08-04。"],[],[],null,["# Integrate with Drive UI's "New" button\n\nWhen a user clicks [Drive UI's \"New\"\nbutton](/workspace/drive/api/guides/about-apps#new) and selects an app in the\nDrive UI, Drive redirects the user to that app's New URL\ndefined in [Configure a Drive UI\nintegration](/workspace/drive/api/guides/enable-sdk).\n\nYour app then receives a default set of template variables within a\n[`state`](/workspace/drive/api/guides/enable-sdk#construct) parameter. The default `state`\ninformation for a New URL is: \n\n {\n \"action\":\"create\",\n \"folderId\":\"\u003cvar translate=\"no\"\u003eFOLDER_ID\u003c/var\u003e\",\n \"folderResourceKey\":\"\u003cvar translate=\"no\"\u003eFOLDER_RESOURCE_KEY\u003c/var\u003e\",\n \"userId\":\"\u003cvar translate=\"no\"\u003eUSER_ID\u003c/var\u003e\"\n }\n\nThis output includes the following values:\n\n- `create`: The action being performed. The value is `create` when a user clicks [Drive UI's \"New\"\n button](/workspace/drive/api/guides/about-apps#new).\n- \u003cvar translate=\"no\"\u003eFOLDER_ID\u003c/var\u003e: The ID of the parent folder.\n- \u003cvar translate=\"no\"\u003eFOLDER_RESOURCE_KEY\u003c/var\u003e: The resource key of the parent folder.\n- \u003cvar translate=\"no\"\u003eUSER_ID\u003c/var\u003e: The profile ID that uniquely identifies the user.\n\nYour app must act on this request by following these steps:\n\n1. Verify that the `action` field has a value of `create`.\n2. Use the `userId` value to create a new session for the user. For more information on signed-in users, see [Users \\& new events](#potential-logins).\n3. Use the [`files.create`](/workspace/drive/api/v3/reference/files/create) method to create a file resource. If `folderId` was set on the request, set the `parents` field to the `folderId` value.\n4. If `folderResourceKey` was set on the request, set the `X-Goog-Drive-Resource-Keys` request header. For more information on resource keys, see [Access link-shared files using resource\n keys](/workspace/drive/api/guides/resource-keys).\n\nThe `state` parameter is URL-encoded, so your app must handle the escape\ncharacters and parse it as JSON.\n\nUsers \\& new events\n-------------------\n\nDrive apps should treat all \"create\" events as potential\nsign-ins. Some users might have multiple accounts, so the user ID in the `state`\nparameter might not match the current session. If the user ID in the `state`\nparameter doesn't match the current session, end the current session for your\napp and sign in as the requested user."]]