Szczegółowe informacje o wspieraniu

Z tego przewodnika dowiesz się, jak używać metody get() w zasobach Membership interfejsu Google Chat API, aby uzyskać szczegółowe informacje o uczestnictwie w pokoju.

Jeśli jesteś administratorem Google Workspace, możesz wywołać metodę get(), aby pobrać szczegóły dotyczące członkostwa w organizacji Google Workspace.

Membership zasób wskazuje, czy użytkownik lub aplikacja Google Chat zostali zaproszeni do pokoju, czy są w nim obecni, czy też są z niego wykluczeni.

Uwierzytelnianie za pomocą uwierzytelniania aplikacji pozwala aplikacji Google Chat uzyskać subskrypcje z pokoi, do których ma dostęp w Google Chat (np. pokoi, których jest członkiem), ale wyklucza subskrypcje aplikacji Google Chat, w tym jej własną. Uwierzytelnianie za pomocą uwierzytelniania użytkownika zwraca członkostwa z pokoi, do których uwierzytelniony użytkownik ma dostęp.

Wymagania wstępne

Node.js

  • Pokój Google Chat, którego użytkownik uwierzytelniony lub wywołująca aplikacja Google Chat jest członkiem. Aby uwierzytelnić się jako aplikacja Google Chat, dodaj ją do pokoju.

Python

  • Pokój Google Chat, którego użytkownik uwierzytelniony lub wywołująca aplikacja Google Chat jest członkiem. Aby uwierzytelnić się jako aplikacja Google Chat, dodaj ją do pokoju.

Java

  • Pokój Google Chat, którego użytkownik uwierzytelniony lub wywołująca aplikacja Google Chat jest członkiem. Aby uwierzytelnić się jako aplikacja Google Chat, dodaj ją do pokoju.

Google Apps Script

  • Pokój Google Chat, którego użytkownik uwierzytelniony lub wywołująca aplikacja Google Chat jest członkiem. Aby uwierzytelnić się jako aplikacja Google Chat, dodaj ją do pokoju.

Sprawdzanie szczegółów subskrypcji

Aby uzyskać szczegółowe informacje o wspieraniu Google Chat, w żądaniu podaj:

  • W przypadku uwierzytelniania aplikacji określ zakres autoryzacji chat.bot. W przypadku uwierzytelniania użytkownika określ zakres uprawnień chat.memberships.readonly lub chat.memberships. Zalecamy wybranie najbardziej ograniczonego zakresu, który nadal pozwala aplikacji na działanie.
  • Wywołaj metodę GetMembership().
  • Przekaż name subskrypcji, aby uzyskać. Uzyskaj nazwę członkostwa z zasobu członkostwa w Google Chat.

Uzyskaj członkostwo z uwierzytelnianiem użytkownika

Aby uzyskać subskrypcję z uwierzytelnianiem użytkownika:

Node.js

chat/client-libraries/cloud/get-membership-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 get membership 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 and MEMBER_NAME here
    name: 'spaces/SPACE_NAME/members/MEMBER_NAME'
  };

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

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

main().catch(console.error);

Python

chat/client-libraries/cloud/get_membership_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 get membership with user credential
def get_membership_with_user_cred():
    # Create a client
    client = create_client_with_user_credentials(SCOPES)

    # Initialize request argument(s)
    request = google_chat.GetMembershipRequest(
        # Replace SPACE_NAME and MEMBER_NAME here
        name = 'spaces/SPACE_NAME/members/MEMBER_NAME',
    )

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

    # Handle the response
    print(response)

get_membership_with_user_cred()

Java

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

// This sample shows how to get membership with user credential.
public class GetMembershipUserCred {

  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))) {
      GetMembershipRequest.Builder request = GetMembershipRequest.newBuilder()
        // replace SPACE_NAME and MEMBERSHIP_NAME here
        .setName("spaces/SPACE_NAME/members/MEMBERSHIP_NAME");
      Membership response = chatServiceClient.getMembership(request.build());

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

Google Apps Script

chat/advanced-service/Main.gs
/**
 * This sample shows how to get membership 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 getMembershipUserCred() {
  // Initialize request argument(s)
  // TODO(developer): Replace SPACE_NAME and MEMBER_NAME here
  const name = 'spaces/SPACE_NAME/members/MEMBER_NAME';

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

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

Aby uruchomić ten przykład, zastąp:

  • SPACE_NAME: identyfikator name pokoju. Identyfikator możesz uzyskać, wywołując metodę ListSpaces() lub z adresu URL pokoju.
  • MEMBER_NAME: identyfikator użytkownika w name. Identyfikator możesz uzyskać, wywołując metodę ListMemberships().

Interfejs Chat API zwraca instancję Membership, która zawiera szczegóły określonego członkostwa.

Uzyskaj członkostwo z uwierzytelnianiem w aplikacji

Aby uzyskać subskrypcję za pomocą uwierzytelniania w aplikacji:

Node.js

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

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

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

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

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

main().catch(console.error);

Python

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

    # Initialize request argument(s)
    request = google_chat.GetMembershipRequest(
        # Replace SPACE_NAME and MEMBER_NAME here
        name = 'spaces/SPACE_NAME/members/MEMBER_NAME',
    )

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

    # Handle the response
    print(response)

get_membership_with_app_cred()

Java

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

// This sample shows how to get membership with app credential.
public class GetMembershipAppCred {

  public static void main(String[] args) throws Exception {
    try (ChatServiceClient chatServiceClient =
        AuthenticationUtils.createClientWithAppCredentials()) {
      GetMembershipRequest.Builder request = GetMembershipRequest.newBuilder()
        // replace SPACE_NAME and MEMBERSHIP_NAME here
        .setName("spaces/SPACE_NAME/members/MEMBERSHIP_NAME");
      Membership response = chatServiceClient.getMembership(request.build());

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

Google Apps Script

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

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

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

Aby uruchomić ten przykład, zastąp:

  • SPACE_NAME: identyfikator name pokoju. Identyfikator możesz uzyskać, wywołując metodę ListSpaces() lub z adresu URL pokoju.
  • MEMBER_NAME: identyfikator użytkownika w name. Identyfikator możesz uzyskać, wywołując metodę ListMemberships().

Interfejs Chat API zwraca instancję Membership, która zawiera szczegóły określonego członkostwa.

Jak uzyskać szczegółowe informacje o subskrypcjach jako administrator Google Workspace

Jeśli jesteś administratorem Google Workspace, możesz wywołać metodę GetMembership(), aby pobrać szczegóły dotyczące członkostwa dowolnego użytkownika w organizacji Google Workspace.

Aby wywołać tę metodę jako administrator Google Workspace:

  • Wywołaj metodę, używając uwierzytelniania użytkownika, i określ zakres autoryzacji, który obsługuje wywoływanie metody przy użyciu uprawnień administratora.
  • W żądaniu ustaw parametr zapytania useAdminAccess na true.

Więcej informacji i przykłady znajdziesz w artykule Zarządzanie pokojami Google Chat przez administratora Google Workspace.