ดูรายละเอียดเกี่ยวกับพื้นที่ทำงาน

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

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

Spaceทรัพยากร แสดงถึงสถานที่ที่ผู้ใช้และแอป Chat สามารถส่งข้อความ แชร์ไฟล์ และทำงานร่วมกันได้ พื้นที่ทำงานมีหลายประเภท ดังนี้

  • ข้อความส่วนตัว (DM) คือการสนทนาระหว่างผู้ใช้ 2 คนหรือผู้ใช้กับแอป Chat
  • แชทกลุ่มคือการสนทนาระหว่างผู้ใช้ตั้งแต่ 3 คนขึ้นไปและแอป Chat
  • พื้นที่ทำงานที่มีชื่อคือพื้นที่ถาวรที่ผู้คนใช้ส่งข้อความ แชร์ไฟล์ และทำงานร่วมกัน

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

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

Node.js

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

Python

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

Java

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

Apps Script

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

รับพื้นที่ทำงาน

หากต้องการรับพื้นที่ใน Google Chat ให้ส่งข้อมูลต่อไปนี้ในคำขอ

ดูรายละเอียดของพื้นที่ทำงานในฐานะผู้ใช้

วิธีดูรายละเอียดพื้นที่โดยใช้การตรวจสอบสิทธิ์ผู้ใช้มีดังนี้

Node.js

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

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

// This sample shows how to get space 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 here
    name: 'spaces/SPACE_NAME',
  };

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

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

main().catch(console.error);

Python

chat/client-libraries/cloud/get_space_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.spaces.readonly"]

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

    # Initialize request argument(s)
    request = google_chat.GetSpaceRequest(
        # Replace SPACE_NAME here
        name = "spaces/SPACE_NAME",
    )

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

    # Handle the response
    print(response)

get_space_with_user_cred()

Java

chat/client-libraries/cloud/src/main/java/com/google/workspace/api/chat/samples/GetSpaceUserCred.java
import com.google.chat.v1.ChatServiceClient;
import com.google.chat.v1.GetSpaceRequest;
import com.google.chat.v1.Space;

// This sample shows how to get space with user credential.
public class GetSpaceUserCred {

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

  public static void main(String[] args) throws Exception {
    try (ChatServiceClient chatServiceClient =
        AuthenticationUtils.createClientWithUserCredentials(
          ImmutableList.of(SCOPE))) {
      GetSpaceRequest.Builder request = GetSpaceRequest.newBuilder()
        // Replace SPACE_NAME here
        .setName("spaces/SPACE_NAME");
      Space response = chatServiceClient.getSpace(request.build());

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

Apps Script

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

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

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

หากต้องการเรียกใช้ตัวอย่างนี้ ให้แทนที่ SPACE_NAME ด้วยรหัสจาก ฟิลด์ name ของพื้นที่ คุณรับรหัสได้โดยเรียกใช้เมธอด ListSpaces() หรือจาก URL ของพื้นที่ทำงาน

Chat API จะแสดงอินสแตนซ์ของ Space ซึ่งแสดงรายละเอียดของพื้นที่ที่ระบุ

ดูรายละเอียดพื้นที่เก็บข้อมูลในฐานะผู้ดูแลระบบ Google Workspace

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

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

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

ดูรายละเอียดของพื้นที่ทำงานในฐานะแอป Chat

วิธีดูรายละเอียดพื้นที่โดยใช้การตรวจสอบสิทธิ์แอปมีดังนี้

Node.js

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

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

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

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

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

main().catch(console.error);

Python

chat/client-libraries/cloud/get_space_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 space with app credential
def get_space_with_app_cred():
    # Create a client
    client = create_client_with_app_credentials()

    # Initialize request argument(s)
    request = google_chat.GetSpaceRequest(
        # Replace SPACE_NAME here
        name = "spaces/SPACE_NAME",
    )

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

    # Handle the response
    print(response)

get_space_with_app_cred()

Java

chat/client-libraries/cloud/src/main/java/com/google/workspace/api/chat/samples/GetSpaceAppCred.java
import com.google.chat.v1.ChatServiceClient;
import com.google.chat.v1.GetSpaceRequest;
import com.google.chat.v1.Space;

// This sample shows how to get space with app credential.
public class GetSpaceAppCred {

  public static void main(String[] args) throws Exception {
    try (ChatServiceClient chatServiceClient =
        AuthenticationUtils.createClientWithAppCredentials()) {
      GetSpaceRequest.Builder request = GetSpaceRequest.newBuilder()
        // Replace SPACE_NAME here
        .setName("spaces/SPACE_NAME");
      Space response = chatServiceClient.getSpace(request.build());

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

Apps Script

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

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

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

หากต้องการเรียกใช้ตัวอย่างนี้ ให้แทนที่ SPACE_NAME ด้วยรหัสจาก ฟิลด์ name ของพื้นที่ คุณรับรหัสได้โดยเรียกใช้เมธอด ListSpaces() หรือจาก URL ของพื้นที่ทำงาน

Chat API จะแสดงอินสแตนซ์ของ Space ซึ่งแสดงรายละเอียดของพื้นที่ที่ระบุ

ข้อจำกัดและข้อควรพิจารณา

  • ฟิลด์ accessSettings predefinedPermissionSettings และ permissionSettings จะแสดงข้อมูลเมื่อคุณตรวจสอบสิทธิ์ด้วยขอบเขต chat.app.spaces เท่านั้น และการตั้งค่าสิทธิ์จะจำกัดไว้เฉพาะพื้นที่ที่แอป Chat สร้างขึ้น