स्पेस के सदस्यों की सूची बनाना

इस गाइड में, Google Chat API के Membership संसाधन पर मौजूद list तरीके का इस्तेमाल करने का तरीका बताया गया है. इससे किसी स्पेस में शामिल सदस्यों की सूची को पेज के हिसाब से दिखाया जा सकता है. साथ ही, स्पेस में शामिल सदस्यों की सूची को फ़िल्टर किया जा सकता है.

स्पेस के मालिक और मैनेजर, यह तय कर सकते हैं कि स्पेस में सदस्यों की सूची किसे दिखे. अगर सदस्यों को देखने की सुविधा पर पाबंदी लगी है, तो ऐप्लिकेशन की पुष्टि करके इस तरीके को कॉल करने पर, हो सकता है कि आपको खाली सूची मिले या उन सदस्यताओं को शामिल न किया जाए जो स्पेस के सदस्यों को नहीं दिखती हैं. उपयोगकर्ता की पुष्टि करके इस तरीके को कॉल करने पर, PERMISSION_DENIED गड़बड़ी दिख सकती है.

  • ऐप्लिकेशन की पुष्टि करके ली गई सदस्यताओं की सूची में, उन स्पेस की सदस्यताएं दिखती हैं जिनका ऐक्सेस Chat ऐप्लिकेशन के पास है. हालांकि, इसमें Chat ऐप्लिकेशन की सदस्यताएं शामिल नहीं होती हैं. इसमें खुद की सदस्यताएं भी शामिल नहीं होती हैं.
  • उपयोगकर्ता की पुष्टि करके सदस्यताएं दिखाने की सुविधा, उन स्पेस की सदस्यताएं दिखाती है जिनका ऐक्सेस पुष्टि किए गए उपयोगकर्ता के पास है.
  • Google Workspace एडमिन के तौर पर, उपयोगकर्ता की पुष्टि करने के लिए एडमिन के विशेषाधिकारों का इस्तेमाल करके, सदस्यताएं देखने की सुविधा मिलती है. इससे आपको अपने Google Workspace संगठन के सभी स्पेस में मौजूद सदस्यताएं दिखती हैं.

Membership संसाधन से पता चलता है कि किसी व्यक्ति या Google Chat ऐप्लिकेशन को किसी स्पेस में शामिल होने का न्योता मिला है या नहीं. इससे यह भी पता चलता है कि वह स्पेस में शामिल है या नहीं.

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

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 ऐप्लिकेशन की सूची बनानी है जिसका ऐक्सेस पुष्टि किए गए उपयोगकर्ता के पास है, तो अपने अनुरोध में यह जानकारी शामिल करें:

  • उपयोगकर्ता की पुष्टि के साथ, chat.memberships.readonly या chat.memberships अनुमति का दायरा तय करें.
  • ListMemberships तरीके को कॉल करें.
  • Google Groups की सूची बनाने के लिए, क्वेरी पैरामीटर showGroups को true पर सेट करें.

यहां दिए गए उदाहरण में, पुष्टि किए गए उपयोगकर्ता को दिखने वाले Google ग्रुप, व्यक्ति, और ऐप्लिकेशन के सदस्यों की सूची दी गई है.

Node.js

chat/client-libraries/cloud/list-memberships-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 list memberships 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
    parent: 'spaces/SPACE_NAME',
    // Filter membership by type (HUMAN or BOT) or role (ROLE_MEMBER or
    // ROLE_MANAGER)
    filter: 'member.type = "HUMAN"',
  };

  // Make the request
  const pageResult = chatClient.listMembershipsAsync(request);

  // Handle the response. Iterating over pageResult will yield results and
  // resolve additional pages automatically.
  for await (const response of pageResult) {
    console.log(response);
  }
}

await main();

Python

chat/client-libraries/cloud/list_memberships_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 list memberships with user credential
def list_memberships_user_cred():
    # Create a client
    client = create_client_with_user_credentials(SCOPES)

    # Initialize request argument(s)
    request = google_chat.ListMembershipsRequest(
        # Replace SPACE_NAME here
        parent = 'spaces/SPACE_NAME',
        # Filter membership by type (HUMAN or BOT) or role (ROLE_MEMBER or
        # ROLE_MANAGER)
        filter = 'member.type = "HUMAN"',
        # Number of results that will be returned at once
        page_size = 100
    )

    # Make the request
    page_result = client.list_memberships(request)

    # Handle the response. Iterating over page_result will yield results and
    # resolve additional pages automatically.
    for response in page_result:
        print(response)

list_memberships_user_cred()

Java

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

// This sample shows how to list memberships with user credential.
public class ListMembershipsUserCred {

  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))) {
      ListMembershipsRequest.Builder request = ListMembershipsRequest.newBuilder()
        // Replace SPACE_NAME here.
        .setParent("spaces/SPACE_NAME")
        // Filter membership by type (HUMAN or BOT) or role
        // (ROLE_MEMBER or ROLE_MANAGER).
        .setFilter("member.type = \"HUMAN\"")
        // Number of results that will be returned at once.
        .setPageSize(10);

      // Iterating over results and resolve additional pages automatically.
      for (Membership response :
          chatServiceClient.listMemberships(request.build()).iterateAll()) {
        System.out.println(JsonFormat.printer().print(response));
      }
    }
  }
}

Apps Script

chat/advanced-service/Main.gs
/**
 * This sample shows how to list memberships 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 listMembershipsUserCred() {
  // Initialize request argument(s)
  // TODO(developer): Replace SPACE_NAME here
  const parent = "spaces/SPACE_NAME";
  // Filter membership by type (HUMAN or BOT) or role (ROLE_MEMBER or
  // ROLE_MANAGER)
  const filter = 'member.type = "HUMAN"';

  // Iterate through the response pages using page tokens
  let responsePage;
  let pageToken = null;
  do {
    // Request response pages
    responsePage = Chat.Spaces.Members.list(parent, {
      filter: filter,
      pageSize: 10,
      pageToken: pageToken,
    });
    // Handle response pages
    if (responsePage.memberships) {
      for (const membership of responsePage.memberships) {
        console.log(membership);
      }
    }
    // Update the page token to the next one
    pageToken = responsePage.nextPageToken;
  } while (pageToken);
}

इस सैंपल को चलाने के लिए, SPACE_NAME की जगह स्पेस के name फ़ील्ड में मौजूद आईडी डालें. आईडी पाने के लिए, ListSpaces तरीके का इस्तेमाल करें या स्पेस के यूआरएल से आईडी पाएं.

Google Chat API, चुने गए स्पेस में शामिल Google ग्रुप, लोगों, और ऐप्लिकेशन के सदस्यों की सूची दिखाता है.

ऐप्लिकेशन की पुष्टि करने की सुविधा वाले स्पेस में सदस्यों की सूची बनाना

उपयोगकर्ताओं और Chat ऐप्लिकेशन को ऐसे स्पेस में लिस्ट करने के लिए जहां पुष्टि किए गए ऐप्लिकेशन को ऐक्सेस करने की अनुमति है, अपने अनुरोध में यह जानकारी शामिल करें:

  • ऐप्लिकेशन की पुष्टि करने की सुविधा का इस्तेमाल करके, chat.bot के लिए अनुमति का दायरा तय करें.
  • ListMemberships तरीके को कॉल करें.
  • Google Groups की सूची बनाने के लिए, क्वेरी पैरामीटर showGroups को true पर सेट करें.

यहां दिए गए उदाहरण में, स्पेस के उन सदस्यों (स्पेस मैनेजर नहीं) की सूची दी गई है जो Chat ऐप्लिकेशन को दिखते हैं:

Node.js

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

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

  // Initialize request argument(s)
  const request = {
    // Replace SPACE_NAME here
    parent: 'spaces/SPACE_NAME',
    // Filter membership by type (HUMAN or BOT) or role (ROLE_MEMBER or
    // ROLE_MANAGER)
    filter: 'member.type = "HUMAN"',
  };

  // Make the request
  const pageResult = chatClient.listMembershipsAsync(request);

  // Handle the response. Iterating over pageResult will yield results and
  // resolve additional pages automatically.
  for await (const response of pageResult) {
    console.log(response);
  }
}

await main();

Python

chat/client-libraries/cloud/list_memberships_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 list memberships with app credential
def list_memberships_app_cred():
    # Create a client
    client = create_client_with_app_credentials()

    # Initialize request argument(s)
    request = google_chat.ListMembershipsRequest(
        # Replace SPACE_NAME here
        parent = 'spaces/SPACE_NAME',
        # Filter membership by type (HUMAN or BOT) or role (ROLE_MEMBER or
        # ROLE_MANAGER)
        filter = 'member.type = "HUMAN"',
        # Number of results that will be returned at once
        page_size = 100
    )

    # Make the request
    page_result = client.list_memberships(request)

    # Handle the response. Iterating over page_result will yield results and
    # resolve additional pages automatically.
    for response in page_result:
        print(response)

list_memberships_app_cred()

Java

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

// This sample shows how to list memberships with app credential.
public class ListMembershipsAppCred {

  public static void main(String[] args) throws Exception {
    try (ChatServiceClient chatServiceClient =
        AuthenticationUtils.createClientWithAppCredentials()) {
      ListMembershipsRequest.Builder request = ListMembershipsRequest.newBuilder()
        // Replace SPACE_NAME here.
        .setParent("spaces/SPACE_NAME")
        // Filter membership by type (HUMAN or BOT) or role
        // (ROLE_MEMBER or ROLE_MANAGER).
        .setFilter("member.type = \"HUMAN\"")
        // Number of results that will be returned at once.
        .setPageSize(10);

      // Iterate over results and resolve additional pages automatically.
      for (Membership response :
          chatServiceClient.listMemberships(request.build()).iterateAll()) {
        System.out.println(JsonFormat.printer().print(response));
      }
    }
  }
}

Apps Script

chat/advanced-service/Main.gs
/**
 * This sample shows how to list memberships with app credential
 *
 * It relies on the OAuth2 scope 'https://www.googleapis.com/auth/chat.bot'
 * used by service accounts.
 */
function listMembershipsAppCred() {
  // Initialize request argument(s)
  // TODO(developer): Replace SPACE_NAME here
  const parent = "spaces/SPACE_NAME";
  // Filter membership by type (HUMAN or BOT) or role (ROLE_MEMBER or
  // ROLE_MANAGER)
  const filter = 'member.type = "HUMAN"';

  // Iterate through the response pages using page tokens
  let responsePage;
  let pageToken = null;
  do {
    // Request response pages
    responsePage = Chat.Spaces.Members.list(
      parent,
      {
        filter: filter,
        pageSize: 10,
        pageToken: pageToken,
      },
      getHeaderWithAppCredentials(),
    );
    // Handle response pages
    if (responsePage.memberships) {
      for (const membership of responsePage.memberships) {
        console.log(membership);
      }
    }
    // Update the page token to the next one
    pageToken = responsePage.nextPageToken;
  } while (pageToken);
}

इस सैंपल को चलाने के लिए, SPACE_NAME की जगह स्पेस के name फ़ील्ड से मिला आईडी डालें. आईडी पाने के लिए, ListSpaces तरीके का इस्तेमाल करें या स्पेस के यूआरएल से आईडी पाएं.

Google Chat API, स्पेस में शामिल लोगों की सूची दिखाता है. इसमें स्पेस मैनेजर शामिल नहीं होते.

Google Workspace एडमिन के तौर पर सदस्यों की सूची बनाना

अगर आप Google Workspace एडमिन हैं, तो अपने Google Workspace संगठन के किसी भी स्पेस के लिए सदस्यताएं देखने के लिए, ListMemberships तरीके का इस्तेमाल करें. Chat API सिर्फ़ आपके संगठन के उपयोगकर्ताओं (इंटरनल और बाहरी, दोनों) या Google ग्रुप की सदस्यताएं दिखाता है. इसलिए, यह किसी भी Chat ऐप्लिकेशन की सदस्यताएं नहीं दिखाता.

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

  • उपयोगकर्ता की पुष्टि करने के लिए, इस तरीके का इस्तेमाल करें. साथ ही, अनुमति का दायरा तय करें. इससे एडमिन के अधिकारों का इस्तेमाल करके, इस तरीके को कॉल किया जा सकेगा.
  • अपने अनुरोध में, इन क्वेरी पैरामीटर के बारे में बताएं:
    • useAdminAccess को true पर सेट करें.
    • सिर्फ़ उपयोगकर्ताओं को वापस लाने के लिए, member.type के लिए filter को HUMAN पर सेट करें.
    • उपयोगकर्ताओं और ग्रुप को वापस लाने के लिए, filter को member.type not equal to BOT AND showGroups equal to true पर सेट करें.

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

पेज नंबर के हिसाब से बांटने की सुविधा को पसंद के मुताबिक बनाएं या सूची को फ़िल्टर करें

सदस्यताओं की सूची बनाने के लिए, यहां दिए गए क्वेरी पैरामीटर पास करें. इससे, सूची में शामिल सदस्यताओं के पेज नंबर को पसंद के मुताबिक बनाया जा सकता है या उन्हें फ़िल्टर किया जा सकता है:

  • pageSize: सदस्यताएं दिखाने की ज़्यादा से ज़्यादा संख्या. ऐसा हो सकता है कि सेवा इस वैल्यू से कम नतीजे दिखाए. यह जानकारी उपलब्ध न होने पर, ज़्यादा से ज़्यादा 100 स्पेस दिखाए जाते हैं. ज़्यादा से ज़्यादा वैल्यू 1,000 हो सकती है. 1,000 से ज़्यादा वैल्यू अपने-आप 1,000 में बदल जाती हैं.
  • pageToken: यह पेज टोकन, list spaces कॉल से मिला है. अगला पेज पाने के लिए, यह टोकन दें. पेज नंबर बदलते समय, फ़िल्टर की वैल्यू उस कॉल से मेल खानी चाहिए जिसने पेज टोकन दिया है. अलग वैल्यू पास करने से, अनचाहे नतीजे मिल सकते हैं.
  • filter: क्वेरी फ़िल्टर. इसके लिए, उपयोगकर्ता की पुष्टि करना ज़रूरी है. क्वेरी की जानकारी से जुड़ी सहायता के लिए, ListMembershipsRequest रेफ़रंस देखें.