במדריך הזה מוסבר איך להשתמש ב-method delete
במשאב membership
של Google Chat API כדי להסיר חבר ממרחב משותף, שנקרא גם מחיקת
מועדון החברים. אי אפשר להסיר מנהלי המרחב המשותף רק אם הם המנהלים שלו
במרחב משותף. לפני שמסירים את המרחב המשותף צריך לבחור משתמש אחר כמנהל של המרחב המשותף
חברויות במועדונים של ערוצים.
משאב אחד (Membership
)
מייצג אם בוצעה הזמנה של משתמש אנושי או של אפליקציית Google Chat,
חלק ממרחב מסוים או חסר בו.
דרישות מוקדמות
Python
- עסק או ארגון חשבון Google Workspace עם גישה אל Google Chat.
- מגדירים את הסביבה:
- יוצרים פרויקט ב-Google Cloud.
- מגדירים את מסך ההסכמה של OAuth.
- מפעילים ומגדירים את Google Chat API עם שם, הסמל והתיאור של אפליקציית Chat.
- להתקין את Python ספריית הלקוח של Google API.
-
יוצרים פרטי כניסה למזהה הלקוח ב-OAuth לאפליקציה למחשב. כדי להריץ את הדוגמה
מדריך, שומרים את פרטי הכניסה כקובץ JSON בשם
client_secrets.json
הספרייה המקומית.
- בוחרים את היקף ההרשאה שתומך באימות משתמש.
איך מסירים אנשים ממרחבים משותפים
כדי להסיר משתמש, קבוצה ב-Google או אפליקציית Chat רווח:
- כדי להסיר משתמש או קבוצה ב-Google, צריך לציין את ההרשאה
chat.memberships
היקף. כדי להסיר אפליקציית Chat, צריך לציין את היקף ההרשאהchat.memberships.app
(אפליקציות יכולות למחוק רק את שלהן) membership; ולא את זה של אפליקציות אחרות). השיטה המומלצת היא לבחור היקף מגביל שעדיין מאפשר לאפליקציה לפעול. - קריאה ל-method
delete
ב משאבmembership
. - כדי למחוק את המינוי, צריך להעביר את
name
של המינוי. אם החברות היא רק מנהלים של המרחב המשותף, צריך קודם להקצות משתמש אחר כמנהל של המרחב המשותף. מחיקת המינוי הזה תימחק.
כך מוחקים מינוי:
Python
- בספריית העבודה, יוצרים קובץ בשם
chat_membership_delete.py
. צריך לכלול את הקוד הבא ב-
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()
בקוד, מחליפים את מה שכתוב בשדות הבאים:
SPACE
: שם של מרחב, שאפשר לקבל ממנו ה-methodspaces.list
מ-Chat API או מכתובת ה-URL של מרחב משותף.MEMBER
: שם המינוי, שאפשר לקבל מהשיטהspaces.members.list
ב-Chat API. כדי למחוק מינוי של אפליקציה, צריך להחליףMEMBER
עםapp
.
בספריית העבודה, יוצרים ומריצים את הדוגמה:
python3 chat_membership_delete.py
אם הפעולה בוצעה ללא שגיאות, גוף התגובה יחזיר את החברות עם
'state': 'NOT_A_MEMBER'
, סימן לכך שהחבר כבר לא במרחב המשותף.
{ "name": "spaces/SPACE/members/MEMBER", "state": "NOT_A_MEMBER" }
נושאים קשורים
- פרטים על המינוי של משתמש או של אפליקציית Chat.
- הצגת רשימת המשתתפים במרחבים משותפים
- איך מעדכנים את פרטי החברות של משתמשים במרחב משותף ב-Google Chat
- איך מזמינים או מוסיפים משתמשים או אפליקציית Chat למרחבים משותפים