|
| 1 | +/** |
| 2 | + * Copyright 2024 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +// [START chat_quickstart] |
| 18 | +/** |
| 19 | + * This quickstart sample shows how to list spaces with user credential |
| 20 | + * |
| 21 | + * It relies on the OAuth2 scope 'https://www.googleapis.com/auth/chat.spaces.readonly' |
| 22 | + * referenced in the manifest file (appsscript.json). |
| 23 | + */ |
| 24 | +function listSpaces() { |
| 25 | + // Initialize request argument(s) |
| 26 | + // Filter spaces by space type (SPACE or GROUP_CHAT or DIRECT_MESSAGE) |
| 27 | + const filter = 'space_type = "SPACE"'; |
| 28 | + |
| 29 | + // Iterate through the response pages using page tokens |
| 30 | + let responsePage; |
| 31 | + let pageToken = null; |
| 32 | + do { |
| 33 | + // Request response pages |
| 34 | + responsePage = Chat.Spaces.list({ |
| 35 | + filter: filter, |
| 36 | + pageToken: pageToken |
| 37 | + }); |
| 38 | + // Handle response pages |
| 39 | + if (responsePage.spaces) { |
| 40 | + responsePage.spaces.forEach((space) => console.log(space)); |
| 41 | + } |
| 42 | + // Update the page token to the next one |
| 43 | + pageToken = responsePage.nextPageToken; |
| 44 | + } while (pageToken); |
| 45 | +} |
| 46 | +// [END chat_quickstart] |
0 commit comments