किसी स्पेस के बारे में जानकारी पाना

इस गाइड में बताया गया है कि Google Chat API के Space संसाधन पर, get() तरीके का इस्तेमाल कैसे किया जाता है. इससे किसी स्पेस के बारे में जानकारी देखी जा सकती है. जैसे, उसका डिसप्ले नेम, ब्यौरा, और दिशा-निर्देश.

अगर आप Google Workspace एडमिन हैं, तो get() तरीके का इस्तेमाल करके, अपने Google Workspace संगठन के किसी भी स्पेस के बारे में जानकारी वापस पा सकते हैं.

Space संसाधन एक ऐसी जगह होती है जहां लोग और Chat ऐप्लिकेशन, मैसेज भेज सकते हैं, फ़ाइलें शेयर कर सकते हैं, और साथ मिलकर काम कर सकते हैं. स्पेस कई तरह के होते हैं:

  • डायरेक्ट मैसेज (डीएम), दो उपयोगकर्ताओं या किसी उपयोगकर्ता और Chat ऐप्लिकेशन के बीच की बातचीत होती है.
  • ग्रुप चैट, तीन या उससे ज़्यादा लोगों और चैट ऐप्लिकेशन के बीच होने वाली बातचीत होती है.
  • नाम वाले स्पेस, ऐसी जगहें होती हैं जहां लोग मैसेज भेजते हैं, फ़ाइलें शेयर करते हैं, और साथ मिलकर काम करते हैं.

ऐप्लिकेशन की पुष्टि करने की सुविधा का इस्तेमाल करके पुष्टि करने से, Chat ऐप्लिकेशन को उस स्पेस के बारे में जानकारी मिलती है जहां Chat ऐप्लिकेशन सदस्य है. उपयोगकर्ता की पुष्टि करके पुष्टि करने से, आपको उन स्पेस का ऐक्सेस मिलता है जिन्हें पुष्टि किए गए उपयोगकर्ता ने ऐक्सेस किया है. ऐसा स्पेस के सदस्य या Google Workspace एडमिन के तौर पर किया जाता है.

ज़रूरी शर्तें

Node.js

  • आपके पास Business या Enterprise वर्शन वाला Google Workspace खाता होना चाहिए. साथ ही, आपके पास Google Chat को ऐक्सेस करने की अनुमति होनी चाहिए.

Python

  • आपके पास Business या Enterprise वर्शन वाला Google Workspace खाता होना चाहिए. साथ ही, आपके पास Google Chat को ऐक्सेस करने की अनुमति होनी चाहिए.

Java

  • आपके पास Business या Enterprise वर्शन वाला Google Workspace खाता होना चाहिए. साथ ही, आपके पास Google Chat को ऐक्सेस करने की अनुमति होनी चाहिए.

Apps Script

  • आपके पास Business या Enterprise वर्शन वाला 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() तरीके का इस्तेमाल करें या स्पेस के यूआरएल से आईडी पाएं.

Chat API, Space का एक इंस्टेंस दिखाता है. इसमें बताए गए स्पेस के बारे में जानकारी होती है.

Google Workspace एडमिन के तौर पर, स्पेस की जानकारी पाना

अगर आप Google Workspace एडमिन हैं, तो GetSpace तरीके का इस्तेमाल करके, अपने Google Workspace संगठन के किसी भी स्पेस के बारे में जानकारी हासिल की जा सकती है.

Google Workspace एडमिन के तौर पर इस तरीके को कॉल करने के लिए, यह तरीका अपनाएं:

  • उपयोगकर्ता की पुष्टि करके, इस तरीके को कॉल करें. साथ ही, अनुमति का दायरा तय करें. इससे एडमिन के अधिकारों का इस्तेमाल करके, इस तरीके को कॉल किया जा सकेगा.
  • अपने अनुरोध में, क्वेरी पैरामीटर useAdminAccess को true पर सेट करें.

ज़्यादा जानकारी और उदाहरणों के लिए, Google Workspace एडमिन के तौर पर Google Chat स्पेस मैनेज करना लेख पढ़ें.

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() तरीके का इस्तेमाल करें या स्पेस के यूआरएल से आईडी पाएं.

Chat API, Space का एक इंस्टेंस दिखाता है. इसमें बताए गए स्पेस के बारे में जानकारी होती है.

सीमाएं और ज़रूरी बातें

  • accessSettings, predefinedPermissionSettings, और permissionSettings फ़ील्ड में सिर्फ़ तब डेटा भरता है, जब chat.app.spaces स्कोप का इस्तेमाल करके पुष्टि की जाती है. साथ ही, अनुमति की सेटिंग सिर्फ़ उन स्पेस के लिए होती हैं जिन्हें Chat ऐप्लिकेशन ने बनाया है.