Integracja z interfejsem Dysku
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Gdy użytkownik kliknie przycisk „Nowy” w interfejsie Dysku i wybierze aplikację w interfejsie Dysku, Dysk przekieruje go na adres URL Nowy tej aplikacji zdefiniowany w konfiguracji integracji z interfejsem Dysku.
Aplikacja otrzymuje domyślny zestaw zmiennych szablonu w parametrze state
. Domyślne state
informacje o nowym adresie URL to:
{
"action":"create",
"folderId":"FOLDER_ID",
"folderResourceKey":"FOLDER_RESOURCE_KEY",
"userId":"USER_ID"
}
Dane wyjściowe zawierają te wartości:
Aplikacja musi zareagować na tę prośbę, wykonując te czynności:
- Sprawdź, czy pole
action
ma wartość create
.
- Użyj wartości
userId
, aby utworzyć nową sesję użytkownika. Więcej informacji o zalogowanych użytkownikach znajdziesz w artykule Użytkownicy i nowe zdarzenia.
- Użyj metody
files.create
, aby utworzyć zasób pliku. Jeśli w żądaniu ustawiono wartość folderId
, ustaw pole parents
na wartość folderId
.
- Jeśli w żądaniu ustawiono wartość
folderResourceKey
, ustaw nagłówek żądania X-Goog-Drive-Resource-Keys
. Więcej informacji o kluczach zasobów znajdziesz w artykule Uzyskiwanie dostępu do plików udostępnionych za pomocą linku przy użyciu kluczy zasobów.
Parametr state
jest zakodowany w formacie adresu URL, więc aplikacja musi obsługiwać znaki ucieczki i parsować go jako JSON.
Użytkownicy i nowe zdarzenia
Aplikacje na Dysku powinny traktować wszystkie zdarzenia „create” jako potencjalne logowania. Niektórzy użytkownicy mogą mieć wiele kont, więc identyfikator użytkownika w parametrze state
może nie pasować do bieżącej sesji. Jeśli identyfikator użytkownika w parametrze state
nie pasuje do bieżącej sesji, zakończ bieżącą sesję w aplikacji i zaloguj się jako użytkownik, który wysłał prośbę.
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-08-04 UTC.
[null,null,["Ostatnia aktualizacja: 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."]]