Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.workspace.api.chat.samples;

import com.google.common.collect.ImmutableList;
import com.google.protobuf.util.JsonFormat;
// [START chat_create_membership_user_cred_for_group]
import com.google.chat.v1.ChatServiceClient;
import com.google.chat.v1.CreateMembershipRequest;
import com.google.chat.v1.Membership;
import com.google.chat.v1.SpaceName;
import com.google.chat.v1.Group;

// This sample shows how to create membership with user credential for a group.
public class CreateMembershipUserCredForGroup {

private static final String SCOPE =
"https://www.googleapis.com/auth/chat.memberships";

public static void main(String[] args) throws Exception {
try (ChatServiceClient chatServiceClient =
AuthenticationUtils.createClientWithUserCredentials(
ImmutableList.of(SCOPE))) {
CreateMembershipRequest.Builder request = CreateMembershipRequest.newBuilder()
// replace SPACE_NAME here
.setParent("spaces/SPACE_NAME")
.setMembership(Membership.newBuilder()
.setGroupMember(Group.newBuilder()
// replace GROUP_NAME here
.setName("groups/GROUP_NAME")));
Membership response = chatServiceClient.createMembership(request.build());

System.out.println(JsonFormat.printer().print(response));
}
}
}
// [END chat_create_membership_user_cred_for_group]
Loading