[null,null,["最后更新时间 (UTC):2025-08-29。"],[[["\u003cp\u003eThe Google Photos Picker API enables users to securely select photos and videos from their Google Photos library for use in your application.\u003c/p\u003e\n"],["\u003cp\u003eSessions manage the photo selection process and can be created, monitored, and deleted using the API.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers should efficiently poll sessions to check for user selections and handle timeouts gracefully.\u003c/p\u003e\n"],["\u003cp\u003eAfter users have made selections, retrieve the media items and clean up the session by deleting it.\u003c/p\u003e\n"],["\u003cp\u003eReview the configuration guide and authorization scopes before implementing the Picker API in your application.\u003c/p\u003e\n"]]],["The Picker API utilizes sessions to securely manage user photo and video selection from Google Photos. Key actions include creating a session with `sessions.create`, generating a `pickerUri` for user interaction, and polling the session via `sessions.get` to monitor `mediaItemsSet` status. Utilize `pollingConfig`'s `pollInterval` and `timeoutIn` for efficient polling. After the selection is complete or if a timeout occurs, clean up the session using `sessions.delete`.\n"],null,["Sessions are at the heart of the Picker API, providing a secure and controlled\nway for users to select photos and videos from their Google Photos library. This\nguide outlines how to create, manage, and effectively poll sessions to enable\nseamless photo selection in your app.\n\nBefore you start\n\n- **Configure your app:** Enable the API and set up authentication. See [Configure your app](/photos/overview/configure-your-app) for detailed steps.\n- **Understand the flow:** Review [get started with the Picker API](/photos/picker/guides/get-started-picker) for an overview of the entire photo selection process.\n- **Review required authorization scopes** : Working with sessions requires the `photospicker.mediaitems.readonly` scope. For more information on scopes, see [Authorization scopes](/photos/overview/authorization).\n\nSession lifecycle\n\nThe Picker API provides methods to create, retrieve information about, and\ndelete sessions. After authenticating your users, you can use sessions to manage\nthe photo picking lifecycle.\n\n1. [Create a session](#create-sessions) to enable a user to select media items.\n2. [Poll the session](#poll-monitor-sessions) to check when the user has finished selecting media items.\n3. [List and retrieve the media items](/photos/picker/guides/media-items).\n4. [Clean up the session](#delete-and-clean) by deleting it.\n\nCreate sessions\n\nCreate a session so your users can securely pick photos directly from their\nGoogle Photos app, and share them back to your application.\n\n`sessions.create` generates a new session, returning a unique `pickerUri` that\nyou can present to your users. The session remains active until either the user\nhas successfully selected media items, or the session times out.\n| **Note:** The `pickerUri` cannot be opened in an iframe due to security reasons.\n\nSession limits\n\nBe aware of session limits. The Picker API enforces limits on the number of\nsessions you can create to ensure responsible usage and prevent abuse. Under\nnormal circumstances, you're unlikely to reach these limits. However, you should\ntrack and [clean up sessions proactively](#delete-and-clean) to avoid any\nissues.\n| **Note:** During development, if you create test sessions without storing their IDs, you won't be able to retrieve or delete them individually. Be mindful of this to avoid creating untracked sessions.\n\nPoll and monitor sessions\n\nOnce a session is created, periodically poll the `sessions.get` endpoint to get\nthe status of a session. The `mediaItemsSet` property in the response returns\n`true` when the user has completed their selection.\n\nMake sure to use efficient polling. The `sessions.get` response includes the\n`pollingConfig` object. Use the following fields to help you avoid unnecessary\ncalls and create a smooth user experience:\n\n- **`pollInterval`**: optimal polling intervals\n- **`timeoutIn`**: timeout duration\n\nSee the [Example polling flow](#example-polling-flow) for more details.\n\nDelete and clean up sessions\n\n`sessions.delete` removes a session, typically used for cleanup after the user\nhas finished selecting media or if the session times out.\n\nIt's a best practice to delete sessions once the user has selected media items\nand [your app has retrieved the media item\nbytes](/photos/picker/guides/media-items).\n\nExample polling flow\n\nThis is an example of creating and polling a session. After first authenticating\nyour user, create a new session.\n\n1. **Create a session:** Call `sessions.create` to initiate a new session and obtain the `pickerUri`.\n2. **Present the `pickerUri` to the user:** Display the URL or generate a QR code for the user to scan. Read an overview of the [user's picking experience](/photos/picker/guides/picking-experience).\n3. **Poll the session:**\n 1. Use the recommended pollInterval from `pollingConfig`.\n 2. Check if `mediaItemsSet` is true.\n 1. If `true`, proceed to list the selected media items.\n 2. If `false`, continue polling until `timeoutIn` is reached.\n 3. Handle timeouts and cancellations gracefully.\n\n GET https://photoslibrary.googleapis.com/v1/sessions/{sessionId}\n\nHere's an example response: \n\n {\n \"id\": string,\n \"pickerUri\": string,\n \"pollingConfig\": {\n object (PollingConfig)\n },\n \"mediaItemsSet\": boolean\n }\n\nPresent the `pickerUri` to the user, and then begin to poll the session.\n\nCheck the response for the following:\n\n- `mediaItemsSet`: true if the user has finished selecting media items\n- `pollingConfig.pollInterval`: recommended time to wait before the next poll\n- `pollingConfig.timeoutIn`: total time to wait before timing out\n\nIf `mediaItemsSet` is false and `timeoutIn` has not been reached, wait for\n`pollInterval` and then poll again.\n\nIf `mediaItemsSet` is true, proceed to list the selected media items.\n\nIf `timeoutIn` is reached, handle the timeout gracefully."]]