瞭解新的 Picker API 和 Library API 的重要異動。詳情請參閱
本文。
Method: sessions.create
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
產生新工作階段,使用者可在該工作階段中選擇要提供給第三方存取的相片和影片。
如果使用者沒有有效的 Google 相簿帳戶,系統會傳回 FAILED_PRECONDITION
錯誤。
如果用戶端應用程式為每位使用者建立太多工作階段,系統會傳回 RESOURCE_EXHAUSTED
錯誤。在一般情況下,客戶不太可能達到這些限制。不過,我們還是建議用戶端在每次工作階段結束後呼叫 sessions.delete
,主動保持在資源限制範圍內。
使用者輕觸「完成」按鈕完成挑選工作階段後,pickerUri
就會失效。建立新工作階段,讓使用者選擇更多相片。
HTTP 要求
POST https://photospicker.googleapis.com/v1/sessions
這個網址使用 gRPC 轉碼語法。
查詢參數
參數 |
requestId |
string
選用設定。用戶端提供的這項要求專屬 ID。 這個 ID 可讓應用程式使用 OAuth 2.0 流程,為輸入裝置有限的裝置提供簡化選擇體驗。 這個 ID 必須採用 UUID (第 4 版) 字串格式,並符合下列規定:
- 不得包含任何使用者的敏感識別資訊。
- 必須包含 32 個十六進位字元,以連字號分為五組,格式為「xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx」(或 8-4-4-4-12)。
|
要求主體
要求主體包含 PickingSession
的例項。
回應主體
如果成功,回應主體會包含新建立的 PickingSession
例項。
授權範圍
需要下列 OAuth 範圍:
https://www.googleapis.com/auth/photospicker.mediaitems.readonly
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-25 (世界標準時間)。
[null,null,["上次更新時間:2025-07-25 (世界標準時間)。"],[[["\u003cp\u003eThis endpoint creates a session for users to select photos and videos for third-party access.\u003c/p\u003e\n"],["\u003cp\u003eA \u003ccode\u003eFAILED_PRECONDITION\u003c/code\u003e error occurs if the user lacks an active Google Photos account.\u003c/p\u003e\n"],["\u003cp\u003eExcessive session creation leads to a \u003ccode\u003eRESOURCE_EXHAUSTED\u003c/code\u003e error, though unlikely under normal use.\u003c/p\u003e\n"],["\u003cp\u003eClients should call \u003ccode\u003esessions.delete\u003c/code\u003e after each session to avoid exceeding resource limits.\u003c/p\u003e\n"],["\u003cp\u003eRequires the \u003ccode\u003ehttps://www.googleapis.com/auth/photospicker.mediaitems.readonly\u003c/code\u003e OAuth scope for authorization.\u003c/p\u003e\n"]]],["This describes the creation of a new session for users to grant third-party access to their photos and videos. It uses a `POST` request to `https://photospicker.googleapis.com/v1/sessions`. The request body contains a `PickingSession` instance, and a successful response returns a new `PickingSession`. Requires `photospicker.mediaitems.readonly` OAuth scope. Errors include `FAILED_PRECONDITION` for inactive accounts and `RESOURCE_EXHAUSTED` for excessive session creation. Deleting sessions with `sessions.delete` is recommended to manage resources.\n"],null,["# Method: sessions.create\n\n- [HTTP request](#body.HTTP_TEMPLATE)\n- [Query parameters](#body.QUERY_PARAMETERS)\n- [Request body](#body.request_body)\n- [Response body](#body.response_body)\n- [Authorization scopes](#body.aspect)\n\nGenerates a new session during which the user can pick photos and videos for third-party access.\n\nIf the user doesn't have an active Google Photos account, a `FAILED_PRECONDITION` error is returned.\n\nIf the client application creates too many sessions per user, a `RESOURCE_EXHAUSTED` error is returned. Clients are unlikely to reach these limits under normal circumstances. However, clients are still recommended to call `sessions.delete` after each session, to proactively stay within resource limits.\n\nOnce [a user taps the **Done**](https://developers.google.com/photos/picker/guides/picking-experience#done_screen) button to complete a picking session, the `pickerUri` will no longer work. Create a new session to allow the user to pick more photos.\n\n### HTTP request\n\n`POST https://photospicker.googleapis.com/v1/sessions`\n\nThe URL uses [gRPC Transcoding](https://google.aip.dev/127) syntax.\n\n### Query parameters\n\n| Parameters ||\n|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `requestId` | `string` Optional. A client-provided unique identifier for this request. This ID is used to enable the streamlined picking experience for applications using the OAuth 2.0 flow for limited-input devices. This ID must have the format of a UUID (version 4) string and follow these requirements: - Must not contain any sensitive identifying information about the user. - Must contain 32 hexadecimal characters divided into five groups separated by hyphens, in the format \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\" (or 8-4-4-4-12). |\n\n### Request body\n\nThe request body contains an instance of [PickingSession](/photos/picker/reference/rest/v1/sessions#PickingSession).\n\n### Response body\n\nIf successful, the response body contains a newly created instance of [PickingSession](/photos/picker/reference/rest/v1/sessions#PickingSession).\n\n### Authorization scopes\n\nRequires the following OAuth scope:\n\n- `https://www.googleapis.com/auth/photospicker.mediaitems.readonly`"]]