Skip to content

Commit 998387e

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

File tree

7 files changed

+352
-0
lines changed

7 files changed

+352
-0
lines changed
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_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 = "SECTION_DISPLAY_NAME"
38+
section.type_ = "CUSTOM_SECTION"
39+
40+
request = chat_v1.CreateSectionRequest(
41+
parent="users/me",
42+
section=section,
43+
)
44+
45+
# Make the request
46+
response = client.create_section(request)
47+
48+
# Handle the response
49+
print(response)
50+
51+
create_section_with_user_cred()
52+
# [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 SECTION_NAME here.
37+
name="SECTION_NAME"
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: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 SECTION_NAME here
37+
parent="SECTION_NAME",
38+
# Number of results that will be returned at once
39+
page_size=10
40+
)
41+
42+
# Make the request
43+
page_result = client.list_section_items(request)
44+
45+
# Handle the response. Iterating over page_result will yield results and
46+
# resolve additional pages automatically.
47+
for item in page_result:
48+
print(item)
49+
50+
list_section_items_with_user_cred()
51+
# [END chat_list_section_items_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_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+
parent="users/me",
36+
# Number of results that will be returned at once
37+
page_size=10
38+
)
39+
40+
# Make the request
41+
page_result = client.list_sections(request)
42+
43+
# Handle the response. Iterating over page_result will yield results and
44+
# resolve additional pages automatically.
45+
for section in page_result:
46+
print(section)
47+
48+
list_sections_with_user_cred()
49+
# [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 SECTION_ITEM_NAME here
37+
name="SECTION_ITEM_NAME",
38+
# Replace TARGET_SECTION_NAME here
39+
target_section="TARGET_SECTION_NAME"
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)