במדריך הזה מוסבר איך להשתמש ב-method patch
במשאב Space
של
להשתמש ב-Google Chat API כדי לעדכן מרחב משותף. לעדכן מרחב כדי לשנות מאפיינים של
שטח, כמו השם המוצג, התיאור וההנחיות שלו למשתמש.
משאב אחד (Space
)
מייצג מקום שבו אנשים ואפליקציות Chat יכולים לשלוח הודעות,
לשתף קבצים ולשתף פעולה. יש כמה סוגים של מרחבים משותפים:
- צ'אטים ישירים הם שיחות בין שני משתמשים או משתמש, אפליקציה ל-Chat.
- צ'אטים קבוצתיים הם שיחות בין שלושה משתמשים או יותר, אפליקציות צ'אט.
- מרחבים עם שם הם מקומות קבועים שבהם אנשים שולחים הודעות, משתפים קבצים, ולשתף פעולה.
דרישות מוקדמות
Python
- עסק או ארגון חשבון Google Workspace עם גישה אל Google Chat.
- מגדירים את הסביבה:
- יוצרים פרויקט ב-Google Cloud.
- מגדירים את מסך ההסכמה של OAuth.
- מפעילים ומגדירים את Google Chat API עם שם, הסמל והתיאור של אפליקציית Chat.
- להתקין את Python ספריית הלקוח של Google API.
-
יוצרים פרטי כניסה למזהה הלקוח ב-OAuth לאפליקציה למחשב. כדי להריץ את הדוגמה
מדריך, שומרים את פרטי הכניסה כקובץ JSON בשם
client_secrets.json
הספרייה המקומית.
- בוחרים את היקף ההרשאה שתומך באימות משתמש.
Node.js
- עסק או ארגון חשבון Google Workspace עם גישה אל Google Chat.
- מגדירים את הסביבה:
- יוצרים פרויקט ב-Google Cloud.
- מגדירים את מסך ההסכמה של OAuth.
- מפעילים ומגדירים את Google Chat API עם שם, הסמל והתיאור של אפליקציית Chat.
- להתקין את Node.js ספריית הלקוח של Google API.
-
יוצרים פרטי כניסה למזהה הלקוח ב-OAuth לאפליקציה למחשב. כדי להריץ את הדוגמה
מדריך, שומרים את פרטי הכניסה כקובץ JSON בשם
client_secrets.json
הספרייה המקומית.
- בוחרים את היקף ההרשאה שתומך באימות משתמש.
איך משנים את המרחב המשותף
כדי לעדכן מרחב משותף קיים ב-Google Chat, צריך להעביר את הפקודה הבאה: בבקשה שלך:
- מציינים את היקף ההרשאה
chat.spaces
. - קוראים לפונקציה
שיטת
patch
במשאבSpace
. לחשבון בבקשה שלך, עליך לציין את השדהname
רווח,updateMask
שדה אחד או יותר לעדכון, וכןbody
עם הפרטים המעודכנים של המרחב המשותף.
אפשר לעדכן פרטים כמו השם המוצג, סוג המרחב, מצב ההיסטוריה עוד. כדי לראות את כל השדות שאפשר לעדכן: במאמרי העזרה.
כך מעדכנים את השדה spaceDetails
במרחב משותף קיים:
Python
- בספריית העבודה, יוצרים קובץ בשם
chat_space_update.py
. צריך לכלול את הקוד הבא ב-
chat_space_update.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.spaces"] def main(): ''' Authenticates with Chat API via user credentials, then updates the specified space description and guidelines. ''' # 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().patch( # The space to update, and the updated space details. # # Replace {space} with a space name. # Obtain the space name from the spaces resource of Chat API, # or from a space's URL. name='spaces/SPACE', updateMask='spaceDetails', body={ 'spaceDetails': { 'description': 'This description was updated with Chat API!', 'guidelines': 'These guidelines were updated with Chat API!' } } ).execute() # Prints details about the updated space. print(result) if __name__ == '__main__': main()
בקוד, מחליפים את
SPACE
בשם של מרחב משותף. שאפשר לקבל אמצעי תשלום אחד (spaces.list
) מ-Chat API או מכתובת ה-URL של מרחב משותף.בספריית העבודה, יוצרים ומריצים את הדוגמה:
python3 chat_space_update.py
Node.js
- בספריית העבודה, יוצרים קובץ בשם
update-space.js
. צריך לכלול את הקוד הבא ב-
update-space.js
:const chat = require('@googleapis/chat'); const {authenticate} = require('@google-cloud/local-auth'); /** * Updates a Chat space with the description and guidelines. * @return {!Promise<!Object>} */ async function updateSpace() { const scopes = [ 'https://www.googleapis.com/auth/chat.spaces', ]; const authClient = await authenticate({scopes, keyfilePath: 'client_secrets.json'}); const chatClient = await chat.chat({version: 'v1', auth: authClient}); return await chatClient.spaces.patch({ name: 'spaces/SPACE', updateMask: 'spaceDetails', requestBody: { spaceDetails: { description: 'This description was updated with Chat API!', guidelines: 'These guidelines were updated with Chat API!' }, } }); } updateSpace().then(console.log);
בקוד, מחליפים את
SPACE
בשם של מרחב משותף. שאפשר לקבל אמצעי תשלום אחד (spaces.list
) מ-Chat API או מכתובת ה-URL של מרחב משותף.בספריית העבודה, מריצים את הדוגמה:
node update-space.js
Google Chat API מחזיר מופע של
משאב אחד (Space
) שמשקף את העדכונים.
נושאים קשורים
- איך מקבלים פרטים על מרחבים משותפים?
- הצגת רשימה של מרחבים
- איך מוחקים מרחבים משותפים
- איך מגדירים מרחב משותף.
- איך מחפשים מרחבים משותפים בצ'אטים ישירים
- להגדיר מרחב משותף שגלוי למשתמשים מסוימים.