स्पेस से किसी उपयोगकर्ता या Google Chat ऐप्लिकेशन को हटाना

इस गाइड में बताया गया है कि स्पेस से उपयोगकर्ता या Chat ऐप्लिकेशन को हटाने के लिए, Google Chat API के membership संसाधन पर delete तरीके का इस्तेमाल कैसे करें. इसे स्पेस से हटाना भी कहा जाता है. अगर स्पेस मैनेजर ही स्पेस मैनेजर हैं, तो उन्हें हटाया नहीं जा सकता. इन सदस्यताओं को हटाने से पहले, किसी दूसरे उपयोगकर्ता को स्पेस मैनेजर बनाएं.

Membership के रिसॉर्स से पता चलता है कि किसी स्पेस में शामिल होने के लिए, किसी उपयोगकर्ता या Google Chat ऐप्लिकेशन को न्योता भेजा गया है या वह स्पेस में शामिल नहीं है.

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

Python

  • Python 3.6 या इससे नया वर्शन
  • pip पैकेज मैनेजमेंट टूल
  • Python के लिए नई Google क्लाइंट लाइब्रेरी. उन्हें इंस्टॉल या अपडेट करने के लिए, अपने कमांड-लाइन इंटरफ़ेस में नीचे दिया गया कमांड चलाएं:

    pip3 install --upgrade google-api-python-client google-auth-oauthlib
    
  • ऐसा Google Cloud प्रोजेक्ट जिसमें Google Chat API चालू हो और उसे कॉन्फ़िगर किया गया हो. तरीका जानने के लिए, Google Chat ऐप्लिकेशन बनाना देखें.
  • Chat ऐप्लिकेशन के लिए अनुमति कॉन्फ़िगर की गई. सदस्यता मिटाने के लिए, ऐसे उपयोगकर्ता से chat.memberships या chat.memberships.app के अनुमति वाले दायरे के साथ उपयोगकर्ता की पुष्टि करनी होगी जिसके पास इस सदस्यता को मिटाने की अनुमति है.

किसी स्पेस से किसी उपयोगकर्ता या Chat ऐप्लिकेशन को हटाना

स्पेस से किसी उपयोगकर्ता या Chat ऐप्लिकेशन को हटाने के लिए:

  • किसी उपयोगकर्ता को हटाने के लिए, chat.memberships की अनुमति का दायरा बताएं. Chat ऐप्लिकेशन को हटाने के लिए, chat.memberships.app अनुमति देने का स्कोप बताएं (ऐप्लिकेशन सिर्फ़ अपनी सदस्यता मिटा सकते हैं, दूसरे ऐप्लिकेशन की सदस्यता नहीं). सबसे सही तरीका यह है कि सबसे प्रतिबंधित स्कोप को चुनें, जिसकी मदद से आपका ऐप्लिकेशन अब भी काम कर सके.
  • membership संसाधन पर delete वाला तरीका कॉल करें.
  • मिटाने के लिए सदस्यता का name पास करें. अगर यह सदस्यता किसी स्पेस के सिर्फ़ स्पेस मैनेजर की है, तो इसे मिटाने से पहले किसी दूसरे उपयोगकर्ता को स्पेस मैनेजर बनाएं.

पैसे चुकाकर ली जाने वाली सदस्यता मिटाने का तरीका:

Python

  1. अपनी वर्किंग डायरेक्ट्री में, chat_membership_delete.py नाम की एक फ़ाइल बनाएं.
  2. chat_membership_delete.py में यह कोड शामिल करें:

    from google_auth_oauthlib.flow import InstalledAppFlow
    from googleapiclient.discovery import build
    
    # Define your app's authorization scopes.
    # When modifying these scopes, delete the file token.json, if it exists.
    SCOPES = ["https://www.googleapis.com/auth/chat.memberships.app"]
    
    def main():
        '''
        Authenticates with Chat API via user credentials,
        then deletes the specified membership.
        '''
    
        # Authenticate with Google Workspace
        # and get user authorization.
        flow = InstalledAppFlow.from_client_secrets_file(
                    'client_secrets.json', SCOPES)
        creds = flow.run_local_server()
    
        # Build a service endpoint for Chat API.
        chat = build('chat', 'v1', credentials=creds)
    
        # Use the service endpoint to call Chat API.
        result = chat.spaces().members().delete(
    
            # The membership to delete.
            #
            # Replace SPACE with a space name.
            # Obtain the space name from the spaces resource of Chat API,
            # or from a space's URL.
            #
            # Replace MEMBER with a membership name.
            # Obtain the membership name from the memberships resource of
            # Chat API. To delete a Chat app's membership, replace MEMBER
            # with app; an alias for the app calling the API.
            name='spaces/SPACE/members/MEMBER'
    
        ).execute()
    
        # Print Chat API's response in your command line interface.
        # When deleting a membership, the response body is empty.
        print(result)
    
    if __name__ == '__main__':
        main()
    
  3. कोड में, इन्हें बदलें:

    • SPACE: स्पेस का नाम, जिसे Chat API में spaces.list तरीके से या स्पेस के यूआरएल से पाया जा सकता है.

    • MEMBER: पैसे चुकाकर ली जाने वाली सदस्यता का नाम, जिसे Chat API में spaces.members.list तरीके से लिया जा सकता है. किसी ऐप्लिकेशन की सदस्यता मिटाने के लिए, MEMBER को app से बदलें.

  4. अपनी वर्किंग डायरेक्ट्री में, यह सैंपल बनाएं और चलाएं:

    python3 chat_membership_delete.py
    

अगर अपील स्वीकार हो जाती है, तो जवाब का मुख्य हिस्सा 'state': 'NOT_A_MEMBER' के साथ सदस्यता की जानकारी देता है. इससे यह पता चलता है कि सदस्य अब स्पेस में नहीं है.

{
    "name": "spaces/SPACE/members/MEMBER",
    "state": "NOT_A_MEMBER"
}