שילוב עם הלחצן "חדש" בממשק המשתמש של Drive
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
כשמשתמש לוחץ על הלחצן 'חדש' בממשק המשתמש של Drive ובוחר אפליקציה בממשק המשתמש של Drive, Drive מפנה מחדש את המשתמש לכתובת ה-URL החדשה של האפליקציה שמוגדרת במאמר הגדרת שילוב של ממשק המשתמש של Drive.
לאחר מכן האפליקציה מקבלת קבוצת משתנים של תבנית שמוגדרת כברירת מחדל בפרמטר state
. ברירת המחדל של state
המידע על כתובת URL חדשה היא:
{
"action":"create",
"folderId":"FOLDER_ID",
"folderResourceKey":"FOLDER_RESOURCE_KEY",
"userId":"USER_ID"
}
הפלט הזה כולל את הערכים הבאים:
create
: הפעולה שמבוצעת. הערך הוא create
כשמשתמש לוחץ על הלחצן 'חדש' בממשק המשתמש של Drive.
- FOLDER_ID: המזהה של תיקיית האב.
- FOLDER_RESOURCE_KEY: מפתח המשאב של תיקיית האב.
- USER_ID: מזהה הפרופיל שמזהה באופן ייחודי את המשתמש.
האפליקציה צריכה לפעול לפי השלבים הבאים בתגובה לבקשה הזו:
- מוודאים שהשדה
action
מכיל את הערך create
.
- משתמשים בערך
userId
כדי ליצור סשן חדש למשתמש. מידע נוסף על משתמשים מחוברים זמין במאמר משתמשים ואירועים חדשים.
- משתמשים ב-method
files.create
כדי ליצור משאב קובץ. אם הערך folderId
הוגדר בבקשה, צריך להגדיר את השדה parents
לערך folderId
.
- אם הכותרת
folderResourceKey
הוגדרה בבקשה, מגדירים את כותרת הבקשה X-Goog-Drive-Resource-Keys
. מידע נוסף על מפתחות משאבים זמין במאמר גישה לקבצים ששותפו באמצעות קישור באמצעות מפתחות משאבים.
הפרמטר state
מקודד בכתובת ה-URL, ולכן האפליקציה צריכה לטפל בתווי הבריחה ולנתח אותו כ-JSON.
משתמשים ואירועים חדשים
אפליקציות של Drive צריכות להתייחס לכל אירוע מסוג create (יצירה) כאל כניסה פוטנציאלית. יכול להיות שלחלק מהמשתמשים יש כמה חשבונות, ולכן מזהה המשתמש בפרמטר state
לא תמיד תואם לסשן הנוכחי. אם מזהה המשתמש בפרמטר state
לא תואם לסשן הנוכחי, צריך לסיים את הסשן הנוכחי באפליקציה ולהיכנס בתור המשתמש המבוקש.
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 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."]]