与云端硬盘界面的“新建”按钮集成
当用户点击 Google 云端硬盘界面的“新建”按钮并在 Google 云端硬盘界面中选择某个应用时,Google 云端硬盘会将用户重定向到配置 Google 云端硬盘界面集成中定义的该应用的新网址。
然后,您的应用会在 state
参数中收到一组默认的模板变量。新网址的默认 state
信息如下:
{
"action":"create",
"folderId":"FOLDER_ID",
"folderResourceKey":"FOLDER_RESOURCE_KEY",
"userId":"USER_ID"
}
此输出包括以下值:
create
:正在执行的操作。当用户点击 Drive 界面的“新建”按钮时,此值为 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-02-24。
[null,null,["最后更新时间 (UTC):2025-02-24。"],[[["When a user creates a new file with your app from Drive UI, your app receives a `state` parameter containing action, folder details, and user ID."],["Your app should verify the `action` is \"create\", create a user session, and use the provided information to create a new file via the Drive API."],["All \"create\" events should be treated as potential sign-ins and handled to accommodate users with multiple accounts, potentially requiring session switching."],["The `state` parameter is URL-encoded and needs to be parsed as JSON by your application for proper data extraction."]]],["When a user selects an app via Drive UI's \"New\" button, Drive redirects to the app's New URL, sending a `state` parameter. The `state` includes `action` (set to \"create\"), `folderId`, `folderResourceKey`, and `userId`. The app must verify the `action`, initiate a new user session based on `userId`, use `files.create` to generate a file resource, and handle `folderId` and `folderResourceKey`. All \"create\" events should be treated as potential sign-ins, with user sessions adjusted accordingly. The `state` parameter is URL-encoded JSON and must be parsed.\n"]]