與雲端硬碟使用者介面整合(&A)
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
使用者點選雲端硬碟 UI 的「新增」按鈕,並在雲端硬碟 UI 中選取應用程式時,雲端硬碟會將使用者重新導向至該應用程式的「新增」網址,該網址是在「設定雲端硬碟 UI 整合」中定義。
應用程式接著會在 state
參數中收到一組預設範本變數。新網址的預設state
資訊如下:
{
"action":"create",
"folderId":"FOLDER_ID",
"folderResourceKey":"FOLDER_RESOURCE_KEY",
"userId":"USER_ID"
}
這項輸出內容包含下列值:
create
:正在執行的動作。使用者點選雲端硬碟使用者介面的「新增」按鈕時,值為 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。
使用者和新事件
雲端硬碟應用程式應將所有「建立」事件視為潛在登入事件。部分使用者可能有多個帳戶,因此 state
參數中的使用者 ID 可能與目前的工作階段不符。如果 state
參數中的使用者 ID 與目前工作階段不符,請結束應用程式的目前工作階段,並以要求的使用者身分登入。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-04 (世界標準時間)。
[null,null,["上次更新時間: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."]]