يوضّح هذا الدليل كيفية استخدام طريقة delete
على مورد Reaction
الخاص بواجهة Google Chat API
لحذف تفاعل من رسالة، مثلاً 👍 و🚲 و مناسبة.
لا يؤدي حذف تفاعل إلى حذف الرسالة.
يمثِّل
المرجع Reaction
رمزًا تعبيريًا يمكن للمستخدِمين استخدامه للتفاعل مع رسالة، مثلاً 👍 و🚲
وعندما.
المتطلبات الأساسية
لغة Python
- الإصدار 3.6 أو إصدار أحدث من Python
- تتيح أداة pip لإدارة الحزم
أحدث مكتبات برامج Google للغة بايثون. ولتثبيتها أو تحديثها، يمكنك تشغيل الأمر التالي في واجهة سطر الأوامر:
pip3 install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib oauth2client
أحد تطبيقات Chat المنشورة. لإنشاء تطبيق Chat ونشره، يمكنك الاطّلاع على إنشاء تطبيق Google Chat.
تم ضبط التفويض لتطبيق Chat. ويتطلب حذف أحد التفاعلات مصادقة المستخدم مع نطاق التفويض
chat.messages.reactions
أوchat.messages
.
حذف تفاعل
لحذف تفاعل من رسالة، أدخِل ما يلي في طلبك:
- حدِّد نطاق التفويض
chat.messages.reactions
أوchat.messages
. - عليك استدعاء
طريقة
delete
في الموردReaction
. - اضبط
name
على اسم المورد للتفاعل المطلوب حذفه.
يتم في المثال التالي حذف التفاعل من الرسالة وتكون:
لغة Python
- في دليل العمل، أنشئ ملفًا باسم
chat_reaction_delete.py
. أدرِج الرمز التالي في
chat_reaction_delete.py
:import os.path from google.auth.transport.requests import Request from google.oauth2.credentials import Credentials from google_auth_oauthlib.flow import InstalledAppFlow from googleapiclient.discovery import build from googleapiclient.errors import HttpError # 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.messages.reactions"] def main(): ''' Authenticates with Chat API via user credentials, then deletes a reaction to a message. ''' # 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().messages().reactions().delete( # The reaction 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 MESSAGE with a message name. # Obtain the message name from the response body returned # after creating a message asynchronously with Chat REST API. # # Replace REACTION with a reaction name. # Obtain the reaction name from the reaction resource of Chat API. name = 'spaces/SPACE/messages/MESSAGE/reactions/REACTION' ).execute() if __name__ == '__main__': main()
في الرمز، استبدل ما يلي:
SPACE
: اسم مساحة، يمكنك الحصول عليه من طريقةspaces.list
في Chat API أو من عنوان URL لمساحة.MESSAGE
: اسم الرسالة الذي يمكنك الحصول عليه من نص الاستجابة الذي يتم عرضه بعد إنشاء رسالة بشكل غير متزامن باستخدام Chat API أو من خلال الاسم المخصّص الذي تم تخصيصه للرسالة عند إنشائهاREACTION
: اسم تفاعل يمكنك الحصول عليه من خلال طريقةspaces.messages.reactions.list
في Chat API أو من نص الاستجابة المعروض بعد إنشاء تفاعل بشكل غير متزامن باستخدام Chat API.
في دليل العمل، أنشئ النموذج وشغِّله:
python3 chat_reaction_delete.py
إذا كانت الاستجابة ناجحة، يكون نص الاستجابة فارغًا، ما يشير إلى أنّه تم حذف التفاعل.