Integrazione con il pulsante"Nuovo " dell'interfaccia utente di Drive
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Quando un utente fa clic sul pulsante "Nuovo" dell'interfaccia utente di Drive e seleziona un'app nell'interfaccia utente di Drive, Drive reindirizza l'utente all'URL Nuovo dell'app definito in Configurare un'integrazione dell'interfaccia utente di Drive.
La tua app riceve quindi un insieme predefinito di variabili del modello all'interno di un parametro
state
. Le informazioni state
predefinite per un nuovo URL sono:
{
"action":"create",
"folderId":"FOLDER_ID",
"folderResourceKey":"FOLDER_RESOURCE_KEY",
"userId":"USER_ID"
}
Questo output include i seguenti valori:
create
: l'azione in corso. Il valore è create
quando un utente
fa clic sul pulsante "Nuovo "
dell'interfaccia utente di Drive.
- FOLDER_ID: l'ID della cartella principale.
- FOLDER_RESOURCE_KEY: la chiave risorsa della cartella principale.
- USER_ID: l'ID profilo che identifica in modo univoco l'utente.
La tua app deve agire in base a questa richiesta seguendo questi passaggi:
- Verifica che il campo
action
abbia il valore create
.
- Utilizza il valore
userId
per creare una nuova sessione per l'utente. Per ulteriori
informazioni sugli utenti che hanno eseguito l'accesso, consulta Utenti ed eventi nuovi.
- Utilizza il metodo
files.create
per
creare una risorsa file. Se folderId
è stato impostato nella richiesta, imposta il campo parents
sul valore folderId
.
- Se
folderResourceKey
è stato impostato nella richiesta, imposta l'intestazione della richiesta X-Goog-Drive-Resource-Keys
. Per saperne di più sulle chiavi
delle risorse, consulta Accedere ai file condivisi tramite link utilizzando le chiavi
delle risorse.
Il parametro state
è codificato tramite URL, quindi la tua app deve gestire i caratteri di escape e analizzarlo come JSON.
Utenti e nuovi eventi
Le app Drive devono trattare tutti gli eventi "create" come potenziali
accessi. Alcuni utenti potrebbero avere più account, quindi l'ID utente nel parametro state
potrebbe non corrispondere alla sessione corrente. Se l'ID utente nel parametro state
non corrisponde alla sessione corrente, termina la sessione corrente per la tua
app e accedi come utente richiesto.
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-08-04 UTC.
[null,null,["Ultimo aggiornamento 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."]]