了解新的 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 用于为使用 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
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):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`"]]