ดูรายละเอียดเกี่ยวกับการเป็นสมาชิก

คู่มือนี้อธิบายวิธีใช้เมธอด get() ในทรัพยากร Membership ของ Google Chat API เพื่อดูรายละเอียดเกี่ยวกับการเป็นสมาชิกในพื้นที่ทำงาน

หากคุณเป็นผู้ดูแลระบบ Google Workspace คุณสามารถเรียกใช้เมธอด get() เพื่อดึงรายละเอียดเกี่ยวกับการเป็นสมาชิกในองค์กร Google Workspace ได้

Membershipทรัพยากร แสดงว่าผู้ใช้ที่เป็นมนุษย์หรือแอป Google Chat ได้รับเชิญให้เข้าร่วม เป็นส่วนหนึ่งของ หรือไม่ได้อยู่ในพื้นที่ทำงาน

การตรวจสอบสิทธิ์ด้วย การตรวจสอบสิทธิ์แอป จะช่วยให้แอป Chat ได้รับการเป็นสมาชิกจากพื้นที่ทำงานที่แอปมี สิทธิ์เข้าถึงใน Google Chat (เช่น พื้นที่ทำงานที่แอปเป็นสมาชิก) แต่จะไม่รวม การเป็นสมาชิกแอป Chat รวมถึงการเป็นสมาชิกของแอปเอง การตรวจสอบสิทธิ์ ด้วย การตรวจสอบสิทธิ์ผู้ใช้ จะแสดงการเป็นสมาชิกจากพื้นที่ทำงานที่ผู้ใช้ที่ได้รับการตรวจสอบสิทธิ์มีสิทธิ์เข้าถึง

ข้อกำหนดเบื้องต้น

Node.js

  • บัญชี Google Workspace สำหรับธุรกิจหรือองค์กร ที่มีสิทธิ์เข้าถึง Google Chat

Python

  • บัญชี Google Workspace สำหรับธุรกิจหรือองค์กร ที่มีสิทธิ์เข้าถึง Google Chat

Java

  • บัญชี Google Workspace สำหรับธุรกิจหรือองค์กร ที่มีสิทธิ์เข้าถึง Google Chat

Apps Script

  • บัญชี Google Workspace สำหรับธุรกิจหรือองค์กร ที่มีสิทธิ์เข้าถึง Google Chat

ดูรายละเอียดเกี่ยวกับการเป็นสมาชิก

หากต้องการดูรายละเอียดเกี่ยวกับการเป็นสมาชิกใน Google Chat ให้ส่งข้อมูลต่อไปนี้ในคำขอ

  • เมื่อใช้การตรวจสอบสิทธิ์ของแอป ให้ระบุchat.botขอบเขตการให้สิทธิ์ เมื่อใช้การตรวจสอบสิทธิ์ของผู้ใช้ ให้ระบุขอบเขตการให้สิทธิ์ chat.memberships.readonly หรือ chat.memberships แนวทางปฏิบัติแนะนำคือเลือกขอบเขตที่จำกัดที่สุดซึ่งยังคง อนุญาตให้แอปทำงานได้
  • เรียกใช้เมธอด GetMembership()
  • ส่งnameของการเป็นสมาชิกเพื่อรับ รับชื่อการเป็นสมาชิกจาก แหล่งข้อมูลการเป็นสมาชิกของ Google Chat

รับการเป็นสมาชิกด้วยการตรวจสอบสิทธิ์ผู้ใช้

วิธีสมัครเป็นสมาชิกโดยใช้การตรวจสอบสิทธิ์ผู้ใช้มีดังนี้

Node.js

chat/client-libraries/cloud/get-membership-user-cred.js
import {createClientWithUserCredentials} from './authentication-utils.js';

const USER_AUTH_OAUTH_SCOPES = ['https://www.googleapis.com/auth/chat.memberships.readonly'];

// This sample shows how to get membership with user credential
async function main() {
  // Create a client
  const chatClient = await createClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);

  // Initialize request argument(s)
  const request = {
    // Replace SPACE_NAME and MEMBER_NAME here
    name: 'spaces/SPACE_NAME/members/MEMBER_NAME'
  };

  // Make the request
  const response = await chatClient.getMembership(request);

  // Handle the response
  console.log(response);
}

main().catch(console.error);

Python

chat/client-libraries/cloud/get_membership_user_cred.py
from authentication_utils import create_client_with_user_credentials
from google.apps import chat_v1 as google_chat

SCOPES = ["https://www.googleapis.com/auth/chat.memberships.readonly"]

# This sample shows how to get membership with user credential
def get_membership_with_user_cred():
    # Create a client
    client = create_client_with_user_credentials(SCOPES)

    # Initialize request argument(s)
    request = google_chat.GetMembershipRequest(
        # Replace SPACE_NAME and MEMBER_NAME here
        name = 'spaces/SPACE_NAME/members/MEMBER_NAME',
    )

    # Make the request
    response = client.get_membership(request)

    # Handle the response
    print(response)

get_membership_with_user_cred()

Java

chat/client-libraries/cloud/src/main/java/com/google/workspace/api/chat/samples/GetMembershipUserCred.java
import com.google.chat.v1.ChatServiceClient;
import com.google.chat.v1.GetMembershipRequest;
import com.google.chat.v1.Membership;

// This sample shows how to get membership with user credential.
public class GetMembershipUserCred {

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

  public static void main(String[] args) throws Exception {
    try (ChatServiceClient chatServiceClient =
        AuthenticationUtils.createClientWithUserCredentials(
          ImmutableList.of(SCOPE))) {
      GetMembershipRequest.Builder request = GetMembershipRequest.newBuilder()
        // replace SPACE_NAME and MEMBERSHIP_NAME here
        .setName("spaces/SPACE_NAME/members/MEMBERSHIP_NAME");
      Membership response = chatServiceClient.getMembership(request.build());

      System.out.println(JsonFormat.printer().print(response));
    }
  }
}

Apps Script

chat/advanced-service/Main.gs
/**
 * This sample shows how to get membership with user credential
 * 
 * It relies on the OAuth2 scope 'https://www.googleapis.com/auth/chat.memberships.readonly'
 * referenced in the manifest file (appsscript.json).
 */
function getMembershipUserCred() {
  // Initialize request argument(s)
  // TODO(developer): Replace SPACE_NAME and MEMBER_NAME here
  const name = 'spaces/SPACE_NAME/members/MEMBER_NAME';

  // Make the request
  const response = Chat.Spaces.Members.get(name);

  // Handle the response
  console.log(response);
}

หากต้องการเรียกใช้ตัวอย่างนี้ ให้แทนที่รายการต่อไปนี้

  • SPACE_NAME: รหัสจากname ของพื้นที่ทำงาน คุณรับรหัสได้โดยเรียกใช้เมธอด ListSpaces() หรือจาก URL ของพื้นที่ทำงาน
  • MEMBER_NAME: รหัสจากnameของสมาชิก คุณรับรหัสได้โดยเรียกใช้เมธอด ListMemberships()

Chat API จะแสดงอินสแตนซ์ของ Membership ซึ่งแสดงรายละเอียดการเป็นสมาชิกที่ระบุ

สมัครเป็นสมาชิกด้วยการตรวจสอบสิทธิ์ของแอป

วิธีสมัครเป็นสมาชิกโดยใช้การตรวจสอบสิทธิ์แอปมีดังนี้

Node.js

chat/client-libraries/cloud/get-membership-app-cred.js
import {createClientWithAppCredentials} from './authentication-utils.js';

// This sample shows how to get membership with app credential
async function main() {
  // Create a client
  const chatClient = createClientWithAppCredentials();

  // Initialize request argument(s)
  const request = {
    // Replace SPACE_NAME and MEMBER_NAME here
    name: 'spaces/SPACE_NAME/members/MEMBER_NAME'
  };

  // Make the request
  const response = await chatClient.getMembership(request);

  // Handle the response
  console.log(response);
}

main().catch(console.error);

Python

chat/client-libraries/cloud/get_membership_app_cred.py
from authentication_utils import create_client_with_app_credentials
from google.apps import chat_v1 as google_chat

# This sample shows how to get membership with app credential
def get_membership_with_app_cred():
    # Create a client
    client = create_client_with_app_credentials()

    # Initialize request argument(s)
    request = google_chat.GetMembershipRequest(
        # Replace SPACE_NAME and MEMBER_NAME here
        name = 'spaces/SPACE_NAME/members/MEMBER_NAME',
    )

    # Make the request
    response = client.get_membership(request)

    # Handle the response
    print(response)

get_membership_with_app_cred()

Java

chat/client-libraries/cloud/src/main/java/com/google/workspace/api/chat/samples/GetMembershipAppCred.java
import com.google.chat.v1.ChatServiceClient;
import com.google.chat.v1.GetMembershipRequest;
import com.google.chat.v1.Membership;

// This sample shows how to get membership with app credential.
public class GetMembershipAppCred {

  public static void main(String[] args) throws Exception {
    try (ChatServiceClient chatServiceClient =
        AuthenticationUtils.createClientWithAppCredentials()) {
      GetMembershipRequest.Builder request = GetMembershipRequest.newBuilder()
        // replace SPACE_NAME and MEMBERSHIP_NAME here
        .setName("spaces/SPACE_NAME/members/MEMBERSHIP_NAME");
      Membership response = chatServiceClient.getMembership(request.build());

      System.out.println(JsonFormat.printer().print(response));
    }
  }
}

Apps Script

chat/advanced-service/Main.gs
/**
 * This sample shows how to get membership with app credential
 * 
 * It relies on the OAuth2 scope 'https://www.googleapis.com/auth/chat.bot'
 * used by service accounts.
 */
function getMembershipAppCred() {
  // Initialize request argument(s)
  // TODO(developer): Replace SPACE_NAME and MEMBER_NAME here
  const name = 'spaces/SPACE_NAME/members/MEMBER_NAME';
  const parameters = {};

  // Make the request
  const response = Chat.Spaces.Members.get(name, parameters, getHeaderWithAppCredentials());

  // Handle the response
  console.log(response);
}

หากต้องการเรียกใช้ตัวอย่างนี้ ให้แทนที่รายการต่อไปนี้

  • SPACE_NAME: รหัสจากname ของพื้นที่ทำงาน คุณรับรหัสได้โดยเรียกใช้เมธอด ListSpaces() หรือจาก URL ของพื้นที่ทำงาน
  • MEMBER_NAME: รหัสจากnameของสมาชิก คุณรับรหัสได้โดยเรียกใช้เมธอด ListMemberships()

Chat API จะแสดงอินสแตนซ์ของ Membership ซึ่งแสดงรายละเอียดการเป็นสมาชิกที่ระบุ

ดูรายละเอียดเกี่ยวกับการเป็นสมาชิกในฐานะผู้ดูแลระบบ Google Workspace

หากคุณเป็นผู้ดูแลระบบ Google Workspace คุณสามารถเรียกใช้เมธอด GetMembership() เพื่อดึงรายละเอียดเกี่ยวกับการเป็นสมาชิกของผู้ใช้ในองค์กร Google Workspace ได้

หากต้องการเรียกใช้เมธอดนี้ในฐานะผู้ดูแลระบบ Google Workspace ให้ทำดังนี้

ดูข้อมูลเพิ่มเติมและตัวอย่างได้ที่หัวข้อจัดการพื้นที่ใน Google Chat ในฐานะผู้ดูแลระบบ Google Workspace