ドライブの UI の [新規] ボタンと統合する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
ユーザーが ドライブ UI の [新規] ボタンをクリックしてドライブ UI でアプリを選択すると、ドライブはユーザーを、ドライブ UI の統合を設定するで定義されたアプリの新規 URL にリダイレクトします。
アプリは、state
パラメータ内でテンプレート変数のデフォルト セットを受け取ります。新しい URL のデフォルトの state
情報は次のとおりです。
{
"action":"create",
"folderId":"FOLDER_ID",
"folderResourceKey":"FOLDER_RESOURCE_KEY",
"userId":"USER_ID"
}
この出力には次の値が含まれます。
create
: 実行中のアクション。ユーザーが ドライブの UI の [新規] ボタンをクリックすると、値は create
になります。
- FOLDER_ID: 親フォルダの ID。
- FOLDER_RESOURCE_KEY: 親フォルダのリソースキー。
- USER_ID: ユーザーを一意に識別するプロファイル ID。
アプリは、次の手順に沿ってこのリクエストに対応する必要があります。
action
フィールドの値が create
であることを確認します。
userId
値を使用して、ユーザーの新しいセッションを作成します。ログイン ユーザーについて詳しくは、ユーザーと新規イベントをご覧ください。
files.create
メソッドを使用して、ファイル リソースを作成します。リクエストで folderId
が設定されている場合は、parents
フィールドを folderId
値に設定します。
- リクエストで
folderResourceKey
が設定されている場合は、X-Goog-Drive-Resource-Keys
リクエスト ヘッダーを設定します。リソースキーの詳細については、リソースキーを使用してリンク共有ファイルにアクセスするをご覧ください。
state
パラメータは URL エンコードされているため、アプリはエスケープ文字を処理して JSON として解析する必要があります。
ユーザーと新しいイベント
ドライブ アプリは、すべての「作成」イベントを潜在的なログインとして扱う必要があります。一部のユーザーは複数のアカウントを持っている可能性があるため、state
パラメータのユーザー ID が現在のセッションと一致しない場合があります。state
パラメータのユーザー ID が現在のセッションと一致しない場合は、アプリの現在のセッションを終了し、リクエストされたユーザーとしてログインします。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 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."]]