ผสานรวมกับปุ่ม "ใหม่" UI ของไดรฟ์
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เมื่อผู้ใช้คลิกปุ่ม "ใหม่" ของ UI ไดรฟ์และเลือกแอปใน
UI ไดรฟ์ ไดรฟ์จะเปลี่ยนเส้นทางผู้ใช้ไปยัง URL ใหม่ของแอปนั้น
ที่กำหนดไว้ในกำหนดค่าการผสานรวม UI ไดรฟ์
จากนั้นแอปจะได้รับชุดตัวแปรเทมเพลตเริ่มต้นภายในพารามิเตอร์
state
state
ข้อมูลเริ่มต้นสำหรับ URL ใหม่มีดังนี้
{
"action":"create",
"folderId":"FOLDER_ID",
"folderResourceKey":"FOLDER_RESOURCE_KEY",
"userId":"USER_ID"
}
เอาต์พุตนี้มีค่าต่อไปนี้
create
: การดำเนินการที่กำลังทำ ค่าจะเป็น create
เมื่อผู้ใช้
คลิกปุ่ม"ใหม่" ของ UI ไดรฟ์
- FOLDER_ID: รหัสของโฟลเดอร์หลัก
- FOLDER_RESOURCE_KEY: คีย์ทรัพยากรของโฟลเดอร์หลัก
- USER_ID: รหัสโปรไฟล์ที่ระบุผู้ใช้
ที่ไม่ซ้ำกัน
แอปของคุณต้องดำเนินการตามคำขอนี้โดยทำตามขั้นตอนต่อไปนี้
- ตรวจสอบว่าฟิลด์
action
มีค่าเป็น create
- ใช้ค่า
userId
เพื่อสร้างเซสชันใหม่สำหรับผู้ใช้ ดูข้อมูลเพิ่มเติมเกี่ยวกับผู้ใช้ที่ลงชื่อเข้าใช้ได้ที่ผู้ใช้และเหตุการณ์ใหม่
- ใช้เมธอด
files.create
เพื่อ
สร้างทรัพยากรไฟล์ หากตั้งค่า folderId
ในคำขอ ให้ตั้งค่าช่อง
parents
เป็นค่า folderId
- หากตั้งค่า
folderResourceKey
ในคำขอ ให้ตั้งค่าส่วนหัวของคำขอ X-Goog-Drive-Resource-Keys
ดูข้อมูลเพิ่มเติมเกี่ยวกับ
คีย์ทรัพยากรได้ที่หัวข้อเข้าถึงไฟล์ที่แชร์ลิงก์โดยใช้คีย์
ทรัพยากร
พารามิเตอร์ state
มีการเข้ารหัส URL ดังนั้นแอปของคุณต้องจัดการอักขระหลีก
และแยกวิเคราะห์เป็น JSON
ผู้ใช้และเหตุการณ์ใหม่
แอปไดรฟ์ควรถือว่าเหตุการณ์ "สร้าง" ทั้งหมดเป็นการลงชื่อเข้าใช้ที่อาจเกิดขึ้น
ผู้ใช้บางรายอาจมีหลายบัญชี ดังนั้นรหัสผู้ใช้ในstate
พารามิเตอร์อาจไม่ตรงกับเซสชันปัจจุบัน หากรหัสผู้ใช้ในพารามิเตอร์ state
ไม่ตรงกับเซสชันปัจจุบัน ให้สิ้นสุดเซสชันปัจจุบันสำหรับแอป
ของคุณ แล้วลงชื่อเข้าใช้ในฐานะผู้ใช้ที่ขอ
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-04 UTC
[null,null,["อัปเดตล่าสุด 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."]]