The following code sample shows how to use an image selector or upload page that users can open from a button in a web app.
This example incorporates Google Picker features such as turning on multi-select, hiding the navigation pane, and choosing the user account with the app's current OAuth 2.0 token.
For this example, need to specify several items:
To locate both the Client ID and the API Key:
In the Google Cloud console, go to Menu > APIs & Services > Credentials.
To locate the App ID:
In the Google Cloud console, go to Menu > IAM & Admin > Settings.
Use the Project number for the app ID.
The same Cloud project must contain both the client ID and the app ID as it's used to authorize access to a user's files.
The setOAuthToken
function allows an app to use the current auth token to
determine which Google Account the Google Picker uses to display the files.
If a user is signed in with multiple Google Accounts, the Google Picker can
display the files of the appropriate authorized account.
After obtaining the file ID from the Google Picker when opening files, an
application can then fetch the file metadata and download the file content as
described in the reference documentation for
files.get
.