Bu kılavuzda, membership
kaynağında patch
yönteminin nasıl kullanılacağı açıklanmaktadır.
Örneğin, Google Chat API'nin üyelikle ilgili özelliklerini değiştirmek,
alan üyesini alan yöneticisine veya alan yöneticisini alan üyesi olarak değiştirebilirsiniz.
İlgili içeriği oluşturmak için kullanılan
Membership
kaynak
bir gerçek kullanıcının veya Google Chat uygulamasının davet edilip edilmediğini
bir alanın parçası olan ya da olmayan
Ö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.
Üyelik güncelleme
Alan üyeliğini güncellemek için isteğinizde aşağıdaki bilgileri iletin:
chat.memberships
yetkilendirme kapsamını belirtin.- Şunu çağırın:
patch
yöntemMembership
kaynağında, ve güncellemek için üyeliktenname
ileupdateMask
ve güncellenen üyelik özelliklerini belirten birbody
ekleyin. updateMask
, üyeliğin güncellenecek özelliklerini belirtir ve şunları içerir:role
: Kullanıcının Chat alanında izin verilen rolü. işlem olarak görebilirsiniz. Olası değerler:ROLE_MEMBER
: Alanın bir üyesidir. Kullanıcı temel izinlere sahiptir. Örneğin, alana mesaj gönderebilirsiniz. 1:1 ve adsız grupta bu rolde herkes rol oynar.ROLE_MANAGER
: Alan yöneticisi. Kullanıcı tüm temel izinlere ve ek olarak alanı yönetmelerine olanak tanıyan yönetim izinlerini (örneğin, kullanıcı ekleme veya üye kaldırılıyor. YalnızcaspaceType
değerininSPACE
olduğu alanlarda desteklenir (adlandırılmış alanlar).
Alandaki normal bir üyeyi alan yöneticisi yapma
Aşağıdaki örnekte,
body
içinde güncellenen üyeliği belirten ROLE_MANAGER
olarak role
özellikler:
Python
- Çalışma dizininizde
chat_membership_update.py
adlı bir dosya oluşturun. Aşağıdaki kodu
chat_membership_update.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.memberships"] def main(): ''' Authenticates with Chat API via user credentials, then updates a specified space member to change it from a regular member to a space manager. ''' # 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().patch( # The membership to update, and the updated role. # # Replace SPACE with a space name. # Obtain the space name from the spaces resource of Chat API, # or from a space's URL. # # Replace MEMBERSHIP with a membership name. # Obtain the membership name from the membership of Chat API. name='spaces/SPACE/members/MEMBERSHIP', updateMask='role', body={'role': 'ROLE_MANAGER'} ).execute() # Prints details about the updated membership. 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.MEMBERSHIP
: bir üyelik adı; şuradan edinebilirsiniz:spaces.members.list
yöntem hakkındaki makalemizi incelemenizi öneririz.
Çalışma dizininizde örneği derleyin ve çalıştırın:
python3 chat_membership_update.py
Node.js
- Çalışma dizininizde
chat_membership_update.js
adlı bir dosya oluşturun. Aşağıdaki kodu
chat_membership_update.js
bölümüne ekleyin:const chat = require('@googleapis/chat'); const {authenticate} = require('@google-cloud/local-auth'); /** * Updates a membership in a Chat space to change it from * a space member to a space manager. * @return {!Promise<!Object>} */ async function updateSpace() { /** * Authenticate with Google Workspace * and get user authorization. */ const scopes = [ 'https://www.googleapis.com/auth/chat.memberships', ]; 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.spaces.patch({ /** * The membership to update, and the updated role. * * Replace SPACE with a space name. * Obtain the space name from the spaces resource of Chat API, * or from a space's URL. * * Replace MEMBERSHIP with a membership name. * Obtain the membership name from the membership of Chat API. */ name: 'spaces/SPACE/members/MEMBERSHIP', updateMask: 'role', requestBody: { role: 'ROLE_MANAGER' } }); } /** * Use the service endpoint to call Chat API. */ updateSpace().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.MEMBERSHIP
: bir üyelik adı; şuradan edinebilirsiniz:spaces.members.list
yöntem hakkındaki makalemizi incelemenizi öneririz.
Çalışma dizininizde örneği derleyin ve çalıştırın:
python3 chat_membership_update.js
Apps Komut Dosyası
Bu örnekte, Gelişmiş Chat Hizmeti.
chat.memberships
yetkilendirme kapsamını Apps Komut Dosyası projesininappsscript.json
dosyası:"oauthScopes": [ "https://www.googleapis.com/auth/chat.memberships" ]
Apps Komut Dosyası projesinin kod:
/** * Updates a membership from space member to space manager. * @param {string} memberName The resource name of the membership. */ function updateMembershipToSpaceManager(memberName) { try { const body = {'role': 'ROLE_MANAGER'}; Chat.Spaces.Members.patch(memberName, body); } catch (err) { // TODO (developer) - Handle exception console.log('Failed to create message with error %s', err.message); } }
Google Chat API, belirtilen üyeliği alan yöneticisi olarak değiştirir ve
Membership
örneği
detaylıca değineceğiz.
Alan yöneticisini normal üye yapma
Aşağıdaki örnekte,
body
içinde güncellenen üyeliği belirten ROLE_MEMBER
olarak role
özellikler:
Python
- Çalışma dizininizde
chat_membership_update.py
adlı bir dosya oluşturun. Aşağıdaki kodu
chat_membership_update.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.memberships"] def main(): ''' Authenticates with Chat API via user credentials, then updates a specified space member to change it from a regular member to a space manager. ''' # 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().patch( # The membership to update, and the updated role. # # Replace SPACE with a space name. # Obtain the space name from the spaces resource of Chat API, # or from a space's URL. # # Replace MEMBERSHIP with a membership name. # Obtain the membership name from the membership of Chat API. name='spaces/SPACE/members/MEMBERSHIP', updateMask='role', body={'role': 'ROLE_MEMBER'} ).execute() # Prints details about the updated membership. 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.MEMBERSHIP
: bir üyelik adı; şuradan edinebilirsiniz:spaces.members.list
yöntem hakkındaki makalemizi incelemenizi öneririz.
Çalışma dizininizde örneği derleyin ve çalıştırın:
python3 chat_membership_update.py
Node.js
- Çalışma dizininizde
chat_membership_update.js
adlı bir dosya oluşturun. Aşağıdaki kodu
chat_membership_update.js
bölümüne ekleyin:const chat = require('@googleapis/chat'); const {authenticate} = require('@google-cloud/local-auth'); /** * Updates a membership in a Chat space to change it from * a space manager to a space member. * @return {!Promise<!Object>} */ async function updateSpace() { /** * Authenticate with Google Workspace * and get user authorization. */ const scopes = [ 'https://www.googleapis.com/auth/chat.memberships', ]; 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.spaces.patch({ /** * The membership to update, and the updated role. * * Replace SPACE with a space name. * Obtain the space name from the spaces resource of Chat API, * or from a space's URL. * * Replace MEMBERSHIP with a membership name. * Obtain the membership name from the membership of Chat API. */ name: 'spaces/SPACE/members/MEMBERSHIP', updateMask: 'role', requestBody: { role: 'ROLE_MEMBER' } }); } /** * Use the service endpoint to call Chat API. */ updateSpace().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.MEMBERSHIP
: bir üyelik adı; şuradan edinebilirsiniz:spaces.members.list
yöntem hakkındaki makalemizi incelemenizi öneririz.
Çalışma dizininizde örneği derleyin ve çalıştırın:
python3 chat_membership_update.js
Apps Komut Dosyası
Bu örnekte, Gelişmiş Chat Hizmeti.
chat.memberships
yetkilendirme kapsamını Apps Komut Dosyası projesininappsscript.json
dosyası:"oauthScopes": [ "https://www.googleapis.com/auth/chat.memberships" ]
Apps Komut Dosyası projesinin kod:
/** * Updates a membership from space manager to space member. * @param {string} memberName The resource name of the membership. */ function updateMembershipToSpaceMember(memberName) { try { const body = {'role': 'ROLE_MEMBER'}; Chat.Spaces.Members.patch(memberName, body); } catch (err) { // TODO (developer) - Handle exception console.log('Failed to create message with error %s', err.message); } }
Google Chat API, belirtilen üyeliği alan yöneticisi olarak değiştirir ve
Membership
örneği
detaylıca değineceğiz.
İlgili konular
- Alana kullanıcı veya Google Chat uygulaması davet edin ya da ekleyin.
- Bir kullanıcının veya Chat uygulamasının üyeliğiyle ilgili ayrıntıları öğrenin.
- Bir alandaki üyeleri listeleyin.
- Bir kullanıcıyı veya Chat uygulamasını alandan kaldırın.