Google Picker 程式碼範例
以下程式碼範例說明如何使用圖片選取器或上傳頁面,讓使用者可透過網頁應用程式中的按鈕開啟。
這個範例整合了 Google Picker 功能,例如開啟多重選取、隱藏導覽窗格,以及使用應用程式的目前 OAuth 2.0 權杖選擇使用者帳戶。
在本例中,您需要指定幾項項目:
如要同時找出用戶端 ID 和API 金鑰:
在 Google Cloud 控制台中,依序前往「選單」圖示 menu
>「API 和服務」
>「憑證」。
前往「憑證」
如要找出應用程式 ID,請按照下列步驟操作:
在 Google Cloud 控制台中,依序前往「Menu」(選單) menu
>「IAM & Admin」(IAM 與管理)>「Settings」(設定)。
前往「設定」
請使用專案編號做為應用程式 ID。
同一個 Cloud 專案必須同時包含用戶端 ID 和應用程式 ID,因為這兩者會用於授權存取使用者的檔案。
setOAuthToken
函式可讓應用程式使用目前的授權權杖,判斷 Google Picker 會使用哪個 Google 帳戶顯示檔案。如果使用者登入多個 Google 帳戶,Google 挑選工具可顯示適當授權帳戶的檔案。
開啟檔案時,應用程式會從 Google Picker 取得檔案 ID,然後依照 files.get
參考文件所述,擷取檔案中繼資料並下載檔案內容。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-01-23 (世界標準時間)。
[null,null,["上次更新時間:2025-01-23 (世界標準時間)。"],[[["This code sample demonstrates how to integrate Google Picker into a web app, allowing users to select or upload images using their Google Drive."],["It utilizes Google Picker features like multi-select, hiding navigation, and leveraging the app's OAuth 2.0 token for user authorization."],["Before running the code, you need to locate your Client ID, API Key, and App ID from the Google Cloud Console."],["The sample code provides functionalities for user authorization, sign-out, and displaying selected file details."]]],[]]