Skip to content

Commit 1e40ae0

Browse files
author
Alice Kim
committed
Add scripts for sections and section items with user credentials
1 parent def0f3e commit 1e40ae0

File tree

7 files changed

+356
-0
lines changed

7 files changed

+356
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2026 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_section_user_cred]
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.users.sections"]
27+
28+
# This sample shows how to create a section of type CUSTOM_SECTION with
29+
# user credential for a human user
30+
def create_section_with_user_cred():
31+
# Create a client
32+
client = create_client_with_user_credentials(SCOPES)
33+
34+
# Initialize request argument(s)
35+
section = chat_v1.Section()
36+
# Replace DISPLAY_NAME here
37+
section.display_name = "DISPLAY_NAME"
38+
section.type_ = "CUSTOM_SECTION"
39+
40+
request = chat_v1.CreateSectionRequest(
41+
# Replace USER here
42+
parent="users/USER",
43+
section=section,
44+
)
45+
46+
# Make the request
47+
response = client.create_section(request)
48+
49+
# Handle the response
50+
print(response)
51+
52+
create_section_with_user_cred()
53+
# [END chat_create_section_user_cred]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2026 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_delete_section_user_cred]
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.users.sections"]
27+
28+
# This sample shows how to delete a section with user credential for a
29+
# human user
30+
def delete_section_with_user_cred():
31+
# Create a client
32+
client = create_client_with_user_credentials(SCOPES)
33+
34+
# Initialize request argument(s)
35+
request = chat_v1.DeleteSectionRequest(
36+
# Replace USER and SECTION here.
37+
name="users/USER/sections/SECTION"
38+
)
39+
40+
# Make the request
41+
response = client.delete_section(request)
42+
43+
# Handle the response
44+
print(response)
45+
46+
delete_section_with_user_cred()
47+
# [END chat_delete_section_user_cred]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2026 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_list_section_items_user_cred]
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.users.sections.readonly"]
27+
28+
# This sample shows how to list section items with user credential for a human
29+
# user
30+
def list_section_items_with_user_cred():
31+
# Create a client
32+
client = create_client_with_user_credentials(SCOPES)
33+
34+
# Initialize request argument(s)
35+
request = chat_v1.ListSectionItemsRequest(
36+
# Replace USER and SECTION here
37+
parent="users/USER/sections/SECTION",
38+
# Replace FILTER here
39+
filter="FILTER",
40+
# Number of results that will be returned at once
41+
page_size=10
42+
)
43+
44+
# Make the request
45+
page_result = client.list_section_items(request)
46+
47+
# Handle the response. Iterating over page_result will yield results and
48+
# resolve additional pages automatically.
49+
for response in page_result:
50+
print(response)
51+
52+
list_section_items_with_user_cred()
53+
# [END chat_list_section_items_user_cred]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2026 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_list_sections_user_cred]
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.users.sections.readonly"]
27+
28+
# This sample shows how to list sections with user credential for a human user
29+
def list_sections_with_user_cred():
30+
# Create a client
31+
client = create_client_with_user_credentials(SCOPES)
32+
33+
# Initialize request argument(s)
34+
request = chat_v1.ListSectionsRequest(
35+
# Replace USER here
36+
parent="users/USER",
37+
# Number of results that will be returned at once
38+
page_size=10
39+
)
40+
41+
# Make the request
42+
page_result = client.list_sections(request)
43+
44+
# Handle the response. Iterating over page_result will yield results and
45+
# resolve additional pages automatically.
46+
for response in page_result:
47+
print(response)
48+
49+
list_sections_with_user_cred()
50+
# [END chat_list_sections_user_cred]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2026 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_move_section_item_user_cred]
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.users.sections"]
27+
28+
# This sample shows how to move a section item with user credential for a human
29+
# user
30+
def move_section_item_with_user_cred():
31+
# Create a client
32+
client = create_client_with_user_credentials(SCOPES)
33+
34+
# Initialize request argument(s)
35+
request = chat_v1.MoveSectionItemRequest(
36+
# Replace USER, SECTION, and ITEM here
37+
name="users/USER/sections/SECTION/items/ITEM",
38+
# Replace USER and SECTION here
39+
target_section="users/USER/sections/SECTION"
40+
)
41+
42+
# Make the request
43+
response = client.move_section_item(request)
44+
45+
# Handle the response
46+
print(response)
47+
48+
move_section_item_with_user_cred()
49+
# [END chat_move_section_item_user_cred]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2026 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_position_section_user_cred]
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.users.sections"]
27+
28+
# This sample shows how to update a sort order of a section with user
29+
# credential for a human user
30+
def position_section_with_user_cred():
31+
# Create a client
32+
client = create_client_with_user_credentials(SCOPES)
33+
34+
# Initialize request argument(s)
35+
request = chat_v1.PositionSectionRequest(
36+
# Replace USER and SECTION here
37+
name="users/USER/sections/SECTION",
38+
# Replace SORT_ORDER here
39+
sort_order=SORT_ORDER,
40+
# Also supports:
41+
# relative_position="START"
42+
# relative_position="END"
43+
)
44+
45+
# Make the request
46+
response = client.position_section(request)
47+
48+
# Handle the response
49+
print(response)
50+
51+
position_section_with_user_cred()
52+
# [END chat_position_section_user_cred]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2026 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_update_section_user_cred]
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.users.sections"]
27+
28+
# This sample shows how to update a display name of a section with user
29+
# credential for a human user
30+
def update_section_with_user_cred():
31+
# Create a client
32+
client = create_client_with_user_credentials(SCOPES)
33+
34+
# Initialize request argument(s)
35+
request = chat_v1.UpdateSectionRequest(
36+
section={
37+
# Replace USER and SECTION here
38+
"name": "users/USER/sections/SECTION",
39+
# Replace DISPLAY_NAME here
40+
"display_name": "DISPLAY_NAME"
41+
},
42+
update_mask="displayName"
43+
)
44+
45+
# Make the request
46+
response = client.update_section(request)
47+
48+
# Handle the response
49+
print(response)
50+
51+
update_section_with_user_cred()
52+
# [END chat_update_section_user_cred]

0 commit comments

Comments
 (0)