Bu kılavuzda, getThreadReadState
yönteminin nasıl kullanılacağı
ThreadReadState
Google Chat API kaynağı.
okuma durumunu öğrenebilirsiniz. Bir iletinin okundu durumunu
boşluk, bkz.
Bir kullanıcının alanının okunma durumuyla ilgili ayrıntıları öğrenin.
İlgili içeriği oluşturmak için kullanılan
ThreadReadState
kaynak
hakkındaki ayrıntıları temsil eden tekil bir kaynaktır:
belirtilen kullanıcının bir Google Chat mesaj dizisinde son okuduğu mesaj.
Ön koşullar
Python
- İşletme veya Kuruluş Şuna erişimi olan Google Workspace hesabı: Google Chat.
- Ortamınızı ayarlayın:
- Bir Google Cloud projesi oluşturun.
- OAuth izin ekranını yapılandırın.
- Google Chat API'yi etkinleştirin ve yapılandırın. Bunun için bir ad girin, Chat uygulamanızın simgesi ve açıklaması.
- Şunu yükleyin: Python Google API İstemci Kitaplığı.
-
Bir masaüstü uygulaması için OAuth istemci kimliği kimlik bilgileri oluşturun. Örneği bu
yoksa, kimlik bilgilerini
client_secrets.json
adlı bir JSON dosyası olarak yerel dizini oluşturun.
- Kullanıcı kimlik doğrulamasını destekleyen bir yetkilendirme kapsamı seçin.
Node.js
- İşletme veya Kuruluş Şuna erişimi olan Google Workspace hesabı: Google Chat.
- Ortamınızı ayarlayın:
- Bir Google Cloud projesi oluşturun.
- OAuth izin ekranını yapılandırın.
- Google Chat API'yi etkinleştirin ve yapılandırın. Bunun için bir ad girin, Chat uygulamanızın simgesi ve açıklaması.
- Şunu yükleyin: Node.js Google API İstemci Kitaplığı.
-
Bir masaüstü uygulaması için OAuth istemci kimliği kimlik bilgileri oluşturun. Örneği bu
yoksa, kimlik bilgilerini
client_secrets.json
adlı bir JSON dosyası olarak yerel dizini oluşturun.
- Kullanıcı kimlik doğrulamasını destekleyen bir yetkilendirme kapsamı seçin.
Apps Komut Dosyası
- İşletme veya Kuruluş Şuna erişimi olan Google Workspace hesabı: Google Chat.
- Ortamınızı ayarlayın:
- Bir Google Cloud projesi oluşturun.
- OAuth izin ekranını yapılandırın.
- Google Chat API'yi etkinleştirin ve yapılandırın. Bunun için bir ad girin, Chat uygulamanızın simgesi ve açıklaması.
- Bağımsız bir Apps Komut Dosyası projesi oluşturun, ve Gelişmiş Sohbet Hizmeti'ni etkinleştirin.
- Kullanıcı kimlik doğrulamasını destekleyen bir yetkilendirme kapsamı seçin.
Arayan kullanıcının ileti dizisi okunma durumunu alma
Bir ileti dizisindeki bir kullanıcının okunma durumuyla ilgili ayrıntıları almak için aşağıdaki bilgileri de ekleyebilirsiniz:
chat.users.readstate
veyachat.users.readstate.readonly
belirtin yetkilendirme kapsamı- Şunu çağırın:
getThreadReadState
yöntem uygulamasındaThreadReadState
kaynak. - Almak için ileti dizisi okuma durumunun
name
değerini iletin. Bu bilgiler kullanıcı kimliği veya takma ad ve alan kimliği girin. İş parçacığının okuma durumunun alınması yalnızca okumanın alınmasını destekler Bu, arayan kullanıcının durumu, takip etmek için:me
takma adı. Örneğin,users/me/spaces/SPACE/threads/THREAD/threadReadState
- Arayan kullanıcının Workspace e-posta adresi. Örneğin,
users/user@example.com/spaces/SPACEthreads/THREAD/threadReadState
- Arayan kullanıcının kullanıcı kimliği. Örneğin,
users/USER/spaces/SPACE/threads/THREAD/threadReadState
Aşağıdaki örnek, arayan kullanıcının ileti dizisi okuma durumunu alır:
Python
- Çalışma dizininizde şu ada sahip bir dosya oluşturun:
chat_threadReadState_get.py
Aşağıdaki kodu
chat_threadReadState_get.py
bölümüne ekleyin: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.users.readstate.readonly"] def main(): ''' Authenticates with Chat API via user credentials, then gets the thread read state for the calling user. ''' # 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.users().spaces().threads().getThreadReadState( # The thread read state to get. # # Replace USER with the calling user's ID, Workspace email, # or the alias me. # # Replace SPACE with a space name. # Obtain the space name from the spaces resource of Chat API, # or from a space's URL. # # Replace THREAD with a thread name. # Obtain the thread name from the messages resource of Chat API. name='users/me/spaces/SPACE/threads/THREAD/threadReadState' ).execute() # Prints the API's response. print(result) if __name__ == '__main__': main()
Bu kodda, aşağıdakini değiştirin:
SPACE
: bir alan adı; şuradan edinebilirsiniz:spaces.list
yöntem API'den veya bir alanın URL'sinden.THREAD
: bir ileti dizisi adı; şuradan edinebilirsiniz:spaces.messages.get
yöntem hakkındaki makalemizi incelemenizi öneririz.
Çalışma dizininizde örneği derleyin ve çalıştırın:
python3 chat_threadReadState_get.py
Node.js
- Çalışma dizininizde şu ada sahip bir dosya oluşturun:
chat_threadReadState_get.js
Aşağıdaki kodu
chat_threadReadState_get
bölümüne ekleyin:const chat = require('@googleapis/chat'); const {authenticate} = require('@google-cloud/local-auth'); /** * Authenticates with Chat API via user credentials, * then gets the thread read state for the calling user. * @return {!Promise<!Object>} */ async function getThreadReadState() { /** * Authenticate with Google Workspace * and get user authorization. */ const scopes = [ 'https://www.googleapis.com/auth/chat.users.readstate.readonly', ]; const authClient = await authenticate({scopes, keyfilePath: 'client_secrets.json'}); /** * Build a service endpoint for Chat API. */ const chatClient = await chat.chat({version: 'v1', auth: authClient}); /** * Use the service endpoint to call Chat API. */ return await chatClient.users.spaces.threads.getThreadReadState({ /** * The thread read state to get. * * Replace USER with the calling user's ID, Workspace email, * or the alias me. * * Replace SPACE with a space name. * Obtain the space name from the spaces resource of Chat API, * or from a space's URL. */ name: 'users/me/spaces/SPACE/threads/THREADS/threadReadState' }); } /** * Use the service endpoint to call Chat API. */ getThreadReadState().then(console.log);
Bu kodda, aşağıdakini değiştirin:
SPACE
: bir alan adı; şuradan edinebilirsiniz:spaces.list
yöntem API'den veya bir alanın URL'sinden.THREAD
: bir ileti dizisi adı; şuradan edinebilirsiniz:spaces.messages.get
yöntem hakkındaki makalemizi incelemenizi öneririz.
Çalışma dizininizde örneği derleyin ve çalıştırın:
node chat_threadReadState_get.js
Apps Komut Dosyası
Bu örnekte, Gelişmiş Chat Hizmeti.
chat.users.readstate.readonly
yetkilendirme kapsamını Apps Komut Dosyası projesininappsscript.json
dosyası:"oauthScopes": [ "https://www.googleapis.com/auth/chat.users.readstate.readonly" ]
Apps Komut Dosyası projesinin kod:
/** * Authenticates with Chat API via user credentials, * then gets the thread read state for the calling user. * @param {string} threadReadStateName The resource name of the thread read state. */ function getThreadReadState(threadReadStateName) { try { Chat.Users.Spaces.Threads.getThreadReadState(threadReadStateName); } catch (err) { // TODO (developer) - Handle exception console.log('Failed to get read state with error %s', err.message); } }
Google Chat API, belirtilen ileti dizisi okuma durumunu alır ve geri döner
örneğinin
ThreadReadState
kaynak.
İlgili konular
- Arayan kullanıcının alan okuma durumunu güncelleyin.
- Arayan kullanıcının alan okuma durumunu öğrenin.