Tích hợp với nút "Mới" của giao diện người dùng Drive
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Khi người dùng nhấp vào nút "Mới" trên giao diện người dùng Drive và chọn một ứng dụng trong giao diện người dùng Drive, Drive sẽ chuyển hướng người dùng đến URL Mới của ứng dụng đó được xác định trong phần Định cấu hình chế độ tích hợp giao diện người dùng Drive.
Sau đó, ứng dụng của bạn sẽ nhận được một bộ biến mẫu mặc định trong tham số state
. Thông tin state
mặc định cho một URL mới là:
{
"action":"create",
"folderId":"FOLDER_ID",
"folderResourceKey":"FOLDER_RESOURCE_KEY",
"userId":"USER_ID"
}
Kết quả này bao gồm các giá trị sau:
create
: Thao tác đang được thực hiện. Giá trị là create
khi người dùng nhấp vào nút "Mới" của giao diện người dùng Drive.
- FOLDER_ID: Mã nhận dạng của thư mục mẹ.
- FOLDER_RESOURCE_KEY: Khoá tài nguyên của thư mục mẹ.
- USER_ID: Mã nhận dạng hồ sơ xác định duy nhất người dùng.
Ứng dụng của bạn phải xử lý yêu cầu này bằng cách làm theo các bước sau:
- Xác minh rằng trường
action
có giá trị là create
.
- Sử dụng giá trị
userId
để tạo một phiên mới cho người dùng. Để biết thêm thông tin về người dùng đã đăng nhập, hãy xem bài viết Người dùng và sự kiện mới.
- Sử dụng phương thức
files.create
để tạo một tài nguyên tệp. Nếu folderId
được đặt trên yêu cầu, hãy đặt trường parents
thành giá trị folderId
.
- Nếu
folderResourceKey
được đặt trên yêu cầu, hãy đặt tiêu đề yêu cầu X-Goog-Drive-Resource-Keys
. Để biết thêm thông tin về khoá tài nguyên, hãy xem bài viết Truy cập vào các tệp được chia sẻ qua đường liên kết bằng khoá tài nguyên.
Tham số state
được mã hoá bằng URL, vì vậy, ứng dụng của bạn phải xử lý các ký tự thoát và phân tích cú pháp tham số này dưới dạng JSON.
Người dùng và sự kiện mới
Các ứng dụng Drive nên coi tất cả sự kiện "tạo" là hoạt động đăng nhập tiềm năng. Một số người dùng có thể có nhiều tài khoản, nên mã nhận dạng người dùng trong tham số state
có thể không khớp với phiên hiện tại. Nếu mã nhận dạng người dùng trong tham số state
không khớp với phiên hiện tại, hãy kết thúc phiên hiện tại cho ứng dụng của bạn và đăng nhập với tư cách là người dùng được yêu cầu.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-04 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-04 UTC."],[],[],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."]]