You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+122-17
Original file line number
Diff line number
Diff line change
@@ -6,14 +6,20 @@
6
6
7
7
## Description
8
8
9
-
The [Google Drive Picker] web components provides a convenient way to integrate the Google Picker API into your web applications. The Google Picker API is a JavaScript API that allows users to select or upload Google Drive files. This component acts as a "File Open" dialog for accessing and interacting with files stored on Google Drive.
9
+
The [Google Drive Picker] web component provides an easy way to integrate the Google Picker API into your web applications. The Google Picker API is a JavaScript API that allows users to select or upload Google Drive files. This component functions as a "File Open" dialog, enabling access to and interaction with files stored on Google Drive.
10
10
11
11
Try the [Demo](https://googleworkspace.github.io/drive-picker-element/?path=/docs/stories-drive-picker--docs).
12
12
13
13
## Index
14
14
15
15
-[Install](#install)
16
16
-[Usage](#usage)
17
+
-[Import the Component](#import-the-component)
18
+
-[Add the Component to Your HTML](#add-the-component-to-your-html)
19
+
-[Use the `oauth-token` attribute](#use-the-oauth-token-attribute)
To use the `drive-picker` component in your project, follow these steps:
45
+
46
+
### Import the Component
47
+
48
+
First, import the `drive-picker` component in your JavaScript file:
49
+
40
50
```js
41
51
import"@googleworkspace/drive-picker-element";
42
52
```
43
53
54
+
This isn't necessary if you're using the CDN version.
55
+
56
+
### Add the Component to Your HTML
57
+
58
+
Next, add the `drive-picker` component to your HTML file. Replace `YOUR_CLIENT_ID` and `YOUR_APP_ID` with your actual client ID and app ID.
59
+
60
+
> Note: You can find these values in the [Google Cloud Console](https://console.cloud.google.com/) under "APIs & Services" > "Credentials". You can also follow this guide to [create a new OAuth 2.0 client ID](https://developers.google.com/identity/oauth2/web/guides/get-google-api-clientid).
> Note: If you wish to register the component with a different name, `import { DrivePickerElement, DrivePickerDocsViewElement } from @googleworkspace/drive-picker-element/drive-picker` and call `customElements.define()` manually.
68
+
> Note: If you wish to register the component with a different name, you can import the components individually and call `customElements.define()` manually:
If you already have an OAuth token, you can pass it to the `drive-picker` component using the `oauth-token` attribute. This will authenticate the user without requiring them to sign in again.
If you don't have an OAuth token, you can listen for the `"picker:authenticated"` event to get the token after the user has authenticated. This library wraps the [Google Identity Servies library](https://developers.google.com/identity/oauth2/web/guides/overview) to make it easier to authenticate users.
91
+
92
+
### Listening to Events
93
+
94
+
The `drive-picker` component emits several events that you can listen to. Here is an example of how to listen to these events:
Most of these events return the [`Picker ResponseObject`](https://developers.google.com/drive/picker/reference/picker.responseobject) as the event detail. For example, the `"picker:picked"``CustomEvent` contains details about the selected files:
Copy file name to clipboardExpand all lines: custom-elements.json
+12-7
Original file line number
Diff line number
Diff line change
@@ -171,7 +171,7 @@
171
171
"declarations": [
172
172
{
173
173
"kind": "class",
174
-
"description": "The `drive-picker` web component provides a convenient way to declaratively\nbuild\n[`google.picker.Picker`](https://developers.google.com/drive/picker/reference/picker)\nby using the component attributes and\n[`google.picker.PickerBuilder`](https://developers.google.com/drive/picker/reference/picker.pickerbuilder)\nand load OAuth tokens.",
174
+
"description": "The `drive-picker` web component provides a convenient way to declaratively\nbuild\n[`google.picker.Picker`](https://developers.google.com/drive/picker/reference/picker)\nby using the component attributes mapped to the corresponding methods of\n[`google.picker.PickerBuilder`](https://developers.google.com/drive/picker/reference/picker.pickerbuilder).",
175
175
"name": "DrivePickerElement",
176
176
"slots": [
177
177
{
@@ -242,7 +242,7 @@
242
242
"privacy": "private",
243
243
"parameters": [
244
244
{
245
-
"name": "data",
245
+
"name": "detail",
246
246
"type": {
247
247
"text": "google.picker.ResponseObject"
248
248
}
@@ -254,7 +254,7 @@
254
254
{
255
255
"name": "picker:authenticated",
256
256
"type": {
257
-
"text": "CustomEvent"
257
+
"text": "{ token: string }"
258
258
},
259
259
"description": "Triggered when the user authenticates with the provided OAuth client ID and scope."
260
260
},
@@ -265,18 +265,23 @@
265
265
}
266
266
},
267
267
{
268
+
"type": {
269
+
"text": "google.picker.ResponseObject"
270
+
},
268
271
"description": "Triggered when the user cancels the picker dialog.",
269
272
"name": "picker:canceled"
270
273
},
271
274
{
275
+
"type": {
276
+
"text": "google.picker.ResponseObject"
277
+
},
272
278
"description": "Triggered when the user picks one or more items.",
273
279
"name": "picker:picked"
274
280
},
275
281
{
276
-
"description": "Triggered when the picker is loaded.",
0 commit comments