الحصول على تفاصيل حول مساحة

يشرح هذا الدليل كيفية استخدام طريقة get() على مورد Space في Google Chat API للاطّلاع على تفاصيل حول مساحة، مثل الاسم المعروض والوصف والإرشادات.

إذا كنت مشرفًا في Google Workspace، يمكنك استدعاء طريقة get() لاسترداد تفاصيل حول أي مساحة في مؤسستك على Google Workspace.

يمثّل المورد Space مكانًا يمكن فيه للمستخدمين وتطبيقات Chat إرسال الرسائل ومشاركة الملفات والتعاون. تتوفّر عدة أنواع من المساحات:

  • الرسائل المباشرة هي محادثات بين مستخدمَين أو بين مستخدم وتطبيق Chat.
  • المحادثات الجماعية هي محادثات بين ثلاثة مستخدمين أو أكثر وتطبيقات Chat.
  • المساحات المسماة هي مساحات دائمة يرسل فيها المستخدمون الرسائل ويشاركون الملفات ويتعاونون.

تتيح المصادقة باستخدام مصادقة التطبيق لتطبيق Chat الحصول على تفاصيل حول مساحة يكون تطبيق Chat عضوًا فيها. تتيح لك المصادقة باستخدام مصادقة المستخدم الحصول على المساحات التي يمكن للمستخدم المصادَق عليه الوصول إليها، إما كعضو في المساحة أو مشرف Google Workspace.

المتطلبات الأساسية

Node.js

Python

Java

برمجة التطبيقات

الحصول على مساحة

للحصول على مساحة في Google Chat، يجب تضمين ما يلي في طلبك:

  • نطاق التفويض:
  • استدعِ الإجراء GetSpace() مع تمرير name الخاص بالمساحة المطلوب الحصول عليها. احصل على اسم المساحة من المورد Space في Google Chat أو من عنوان URL الخاص بالمساحة.

الحصول على تفاصيل المساحة كمستخدم

إليك كيفية الحصول على تفاصيل المساحة باستخدام مصادقة المستخدم:

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));
    }
  }
}

برمجة التطبيقات

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، اتّبِع الخطوات التالية:

  • استدعِ الطريقة باستخدام مصادقة المستخدم، وحدِّد نطاق تفويض يتيح استدعاء الطريقة باستخدام امتيازات المشرف.
  • في طلبك، حدِّد مَعلمة طلب البحث useAdminAccess على true.

لمزيد من المعلومات والأمثلة، يُرجى الاطّلاع على مقالة إدارة مساحات 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));
    }
  }
}

برمجة التطبيقات

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 يتضمّن تفاصيل المساحة المحدّدة.

القيود والاعتبارات