Learn about the new Picker API and important Library API changes.
Details here.
Picker API 使用入门
Picker API 可让用户安全地从其 Google 相册库中选择照片和视频,并与您的应用分享。
前期准备
Picker API 流程
下面简要介绍了 Picker API 的运作方式:
检查 OAuth 令牌:在开始 Picker API 流程之前,请检查用户是否有有效的 OAuth 2.0 访问令牌。如果没有令牌,请启动 OAuth 2.0 授权流程来获取令牌。
创建会话:通过调用 Picker API 来创建新会话,启动该过程。此调用将返回唯一的 pickerUri
。
将用户定向至 Google 相册应用:向用户提供 pickerUri
(可采用可点击的链接或二维码的形式)。此网址将安全地打开用户的 Google 相册应用。
用户选择媒体内容:在 Google 相册应用中,用户可以浏览自己的媒体库,并选择要与您的应用分享的照片和视频。请参阅用户选择体验概览。
轮询会话:您的应用应定期轮询会话以检查状态。您希望 mediaItemsSet
属性返回 true,以指示用户已完成选择。
列出所选媒体项:mediaItemsSet
返回 true 后,您可以使用 list 方法获取有关所选媒体项的详细信息。
检索和使用媒体内容:现在,您可以访问所选媒体内容了。您可以使用 baseUrl
提取其内容,并在应用中加以利用。
后续步骤
- 查看参考文档:浏览详细的 Picker API 参考文档,了解所有可用的方法和参数。
- 试用示例:查看我们的示例,了解 Picker API 的实际运用,并从中获得集成方面的灵感。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-11-08。
[null,null,["最后更新时间 (UTC):2024-11-08。"],[[["The Picker API lets users securely select photos and videos from their Google Photos library and share them with your application."],["Before using the Picker API, ensure it's the right fit for your use case and properly configure your app with the necessary API and authentication setup."],["The Picker API flow involves creating a session, directing users to the Google Photos app for selection, polling the session for completion, and then retrieving the selected media items."],["Developers should check the provided resources like reference documentation and samples for detailed information and implementation examples."]]],[]]