|
| 1 | +# -*- coding: utf-8 -*- |
| 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 | +# http://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 | +# It may require modifications to work in your environment. |
| 17 | + |
| 18 | +# To install the latest published package dependency, execute the following: |
| 19 | +# python3 -m pip install google-apps-chat |
| 20 | + |
| 21 | +# [START chat_set_up_space_user_cred] |
| 22 | +from authentication_utils import create_client_with_user_credentials |
| 23 | +from google.apps import chat_v1 as google_chat |
| 24 | + |
| 25 | +SCOPES = ["https://www.googleapis.com/auth/chat.spaces.create"] |
| 26 | + |
| 27 | +def set_up_space_with_user_cred(): |
| 28 | + # Create a client |
| 29 | + client = create_client_with_user_credentials(SCOPES) |
| 30 | + |
| 31 | + # Initialize request argument(s) |
| 32 | + request = google_chat.SetUpSpaceRequest( |
| 33 | + space = { |
| 34 | + "space_type": 'SPACE', |
| 35 | + # Replace DISPLAY_NAME here. |
| 36 | + "display_name": 'DISPLAY_NAME' |
| 37 | + }, |
| 38 | + memberships = [{ |
| 39 | + "member": { |
| 40 | + # Replace USER_NAME here. |
| 41 | + "name": 'users/USER_NAME', |
| 42 | + "type_": 'HUMAN' |
| 43 | + } |
| 44 | + }] |
| 45 | + ) |
| 46 | + |
| 47 | + # Make the request |
| 48 | + response = client.set_up_space(request) |
| 49 | + |
| 50 | + # Handle the response |
| 51 | + print(response) |
| 52 | + |
| 53 | +set_up_space_with_user_cred() |
| 54 | + |
| 55 | +# [END chat_set_up_space_user_cred] |
0 commit comments