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

คู่มือนี้จะอธิบายวิธีใช้เมธอด 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 รุ่น Business หรือ Enterprise ที่มีสิทธิ์เข้าถึง Google Chat

Python

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

Java

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

Apps Script

  • บัญชี Google Workspace รุ่น Business หรือ Enterprise ที่มีสิทธิ์เข้าถึง 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 สร้างขึ้น