|
| 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 | + |
| 22 | +# [START chat_create_membership_user_cred_for_group] |
| 23 | +from authentication_utils import create_client_with_user_credentials |
| 24 | +from google.apps import chat_v1 as google_chat |
| 25 | + |
| 26 | +SCOPES = ["https://www.googleapis.com/auth/chat.memberships"] |
| 27 | + |
| 28 | +# This sample shows how to create membership with user credential for a group |
| 29 | +def create_membership_with_user_cred_for_group(): |
| 30 | + # Create a client |
| 31 | + client = create_client_with_user_credentials(SCOPES) |
| 32 | + |
| 33 | + # Initialize request argument(s) |
| 34 | + request = google_chat.CreateMembershipRequest( |
| 35 | + # Replace SPACE_NAME here |
| 36 | + parent = "spaces/SPACE_NAME", |
| 37 | + membership = { |
| 38 | + "groupMember": { |
| 39 | + # Replace GROUP_NAME here |
| 40 | + "name": "groups/GROUP_NAME" |
| 41 | + } |
| 42 | + } |
| 43 | + ) |
| 44 | + |
| 45 | + # Make the request |
| 46 | + response = client.create_membership(request) |
| 47 | + |
| 48 | + # Handle the response |
| 49 | + print(response) |
| 50 | + |
| 51 | +create_membership_with_user_cred_for_group() |
| 52 | + |
| 53 | +# [END chat_create_membership_user_cred_for_group] |
0 commit comments