2025 年 4 月 1 日,Library API 中的部分範圍已遭到移除。
詳情請參閱這篇文章。
開始使用 Picker API
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Picker API 提供安全的方式,讓使用者從 Google 相簿媒體庫中選取相片和影片,並與您的應用程式分享。
事前準備
Picker API 流程
以下簡要說明 Picker API 的運作方式:
檢查 OAuth 權杖:在開始使用 Picker API 流程之前,請檢查使用者是否有有效的 OAuth 2.0 存取權杖。如果沒有權杖,請啟動 OAuth 2.0 授權流程來取得權杖。
建立工作階段:呼叫 Picker API 來建立新工作階段,即可啟動程序。這個呼叫會傳回一個專屬的 pickerUri
。
將使用者導向 Google 相簿應用程式:提供 pickerUri
給使用者 (可點選連結或 QR code)。這個網址將安全地開啟其 Google 相簿應用程式。
使用者選取媒體項目:在 Google 相簿應用程式中,使用者可以瀏覽媒體庫,並選取要與應用程式分享的相片和影片。詳情請參閱「使用者的選擇體驗」總覽。
輪詢工作階段:應用程式應定期輪詢工作階段來檢查狀態。您希望 mediaItemsSet
屬性傳回 true,表示使用者已完成選取作業。
列出選取的媒體項目:mediaItemsSet
傳回 true 後,您可以使用清單方法取得所選媒體項目的詳細資料。
擷取及使用媒體項目:您現在可以存取所選媒體項目。您可以使用 baseUrl
擷取內容,並在應用程式中加以利用。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間:2025-08-29 (世界標準時間)。"],[[["\u003cp\u003eThe Picker API lets users securely select photos and videos from their Google Photos library and share them with your application.\u003c/p\u003e\n"],["\u003cp\u003eBefore 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.\u003c/p\u003e\n"],["\u003cp\u003eThe 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.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers should check the provided resources like reference documentation and samples for detailed information and implementation examples.\u003c/p\u003e\n"]]],["The Picker API enables users to share media from Google Photos with your app. First, check for and obtain an OAuth token. Then, create a new session via the Picker API, generating a `pickerUri`. Direct users to this URI to select media. Periodically poll the session until `mediaItemsSet` is true. Use the list method to retrieve details of selected items, and then access their content using `baseUrl` for use in your application.\n"],null,["# Get started with the Picker API\n\nThe Picker API provides a secure way for your users to select photos and videos\nfrom their Google Photos library and share them with your application.\n\nBefore you start\n----------------\n\n- **Check out the overview:** [Compare the Picker API and the Library API](/photos/overview/about) to make sure the Picker API is the right fit for your use case.\n- **Configure your app:** Enable the API and set up authentication. See [Configure your app](/photos/overview/configure-your-app) for detailed steps.\n\nThe Picker API flow\n-------------------\n\nHere is an overview of the how the Picker API works:\n\n1. **Check for OAuth token:** Before starting the Picker API flow, check for a\n valid OAuth 2.0 access token for the user. If there is no token, [initiate\n the OAuth 2.0 authorization flow](/identity/protocols/oauth2) to obtain one.\n\n2. **Create a session:** Initiate the process by making a call to the Picker\n API to [create a new\n session](/photos/picker/reference/rest/v1/sessions/create). This call will\n return a unique `pickerUri`.\n\n3. **Direct users to the Google Photos app:** Provide the [`pickerUri`](/photos/picker/reference/rest/v1/sessions#PickingSession.FIELDS.picker_uri)\n to your users (either as a clickable link or a QR code). This URL will\n securely open their Google Photos app.\n\n4. **User selects media items:** Within the Google Photos app, users can browse\n their library and select the photos and videos they want to share with your\n app. Read an overview of the [user's picking experience](/photos/picker/guides/picking-experience).\n\n5. **Poll the session:** Your app should periodically [poll the session](/photos/picker/reference/rest/v1/sessions/get)\n to check the status. You're looking for the\n [`mediaItemsSet`](/photos/picker/reference/rest/v1/sessions#PickingSession.FIELDS.media_items_set)\n property to return true, indicating the user has finished their selection.\n\n | **Note:** Every time you poll a session the response contains [recommended\n | intervals and\n | timeouts](/photos/picker/reference/rest/v1/sessions#PollingConfig) to configure your polling.\n6. **List selected media items:** Once `mediaItemsSet` returns true, you can\n use [the list method](/photos/picker/reference/rest/v1/mediaItems/list) to\n get details about the selected media items.\n\n7. **Retrieve and use media items:** Now you have access to the selected media\n items. You can [fetch their\n content](/photos/picker/guides/media-items#retrieve-picked-media-items)\n using the\n [`baseUrl`](/photos/picker/reference/rest/v1/mediaItems#MediaFile.FIELDS.base_url)\n and utilize them within your application.\n\nNext steps\n----------\n\n- Review the reference docs: Explore the detailed [Picker API reference\n documentation](/photos/picker/reference/rest) to learn about all the available methods and parameters.\n- Try out the samples: Check out our [sample](/photos/picker/samples) to see the Picker API in action and get inspiration for your integration."]]