|
| 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 | +package com.google.workspace.api.chat.samples; |
| 18 | + |
| 19 | +import com.google.common.collect.ImmutableList; |
| 20 | +import com.google.protobuf.util.JsonFormat; |
| 21 | + |
| 22 | +// [START chat_set_up_space_user_cred] |
| 23 | +import com.google.chat.v1.ChatServiceClient; |
| 24 | +import com.google.chat.v1.Membership; |
| 25 | +import com.google.chat.v1.SetUpSpaceRequest; |
| 26 | +import com.google.chat.v1.Space; |
| 27 | +import com.google.chat.v1.User; |
| 28 | + |
| 29 | +// This sample shows how to set up a named space with one initial member with |
| 30 | +// user credential. |
| 31 | +public class SetUpSpaceUserCred { |
| 32 | + |
| 33 | + private static final String SCOPE = |
| 34 | + "https://www.googleapis.com/auth/chat.spaces.create"; |
| 35 | + |
| 36 | + public static void main(String[] args) throws Exception { |
| 37 | + try (ChatServiceClient chatServiceClient = |
| 38 | + AuthenticationUtils.createClientWithUserCredentials( |
| 39 | + ImmutableList.of(SCOPE))) { |
| 40 | + SetUpSpaceRequest.Builder request = SetUpSpaceRequest.newBuilder() |
| 41 | + .setSpace(Space.newBuilder() |
| 42 | + .setSpaceType(Space.SpaceType.SPACE) |
| 43 | + // Replace DISPLAY_NAME here. |
| 44 | + .setDisplayName("DISPLAY_NAME")) |
| 45 | + .addAllMemberships(ImmutableList.of(Membership.newBuilder() |
| 46 | + .setMember(User.newBuilder() |
| 47 | + // Replace USER_NAME here. |
| 48 | + .setName("users/USER_NAME") |
| 49 | + .setType(User.Type.HUMAN)).build())); |
| 50 | + Space response = chatServiceClient.setUpSpace(request.build()); |
| 51 | + |
| 52 | + System.out.println(JsonFormat.printer().print(response)); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
| 56 | +// [END chat_set_up_space_user_cred] |
0 commit comments