'Consult chat reports using admin sdk google workspace
I'm new to integrations with the API SDK GOOGLE, and I need to consume the Workspace activity reports regarding the use of google Chat, I configured the following code, but I believe it is wrong, I didn't find a documentation that helps me to validate the form correct way to make calls to the reports api
from oauth2client.service_account import ServiceAccountCredentials
from httplib2 import Http
from apiclient.discovery import build
import googleapiclient.discovery
#escopos necessarios
scopes = [
'https://www.googleapis.com/auth/admin.reports.usage.readonly',
'https://www.googleapis.com/auth/drive.metadata.readonly',
'https://www.googleapis.com/auth/admin.reports.usage.readonly',
'https://www.googleapis.com/auth/admin.reports.audit.readonly',
'https://www.googleapis.com/auth/analytics',
'https://www.googleapis.com/auth/analytics.readonly',
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/apps.alerts',
'https://www.googleapis.com/auth/apps.order.readonly',
'https://www.googleapis.com/auth/apps.order',
'https://www.googleapis.com/auth/admin.directory.user.readonly',
'https://www.googleapis.com/auth/admin.directory.domain',
'https://www.googleapis.com/auth/admin.directory.domain.readonly',
'https://www.googleapis.com/auth/calendar.readonly' ,
'https://www.googleapis.com/auth/drive.readonly',
'https://www.googleapis.com/auth/admin.directory.user',
'https://www.googleapis.com/auth/cloud-platform'
]
#dominio que sera pesquisado
TARGET='dominio.test.com'
#credenciais de acesso
credentials = ServiceAccountCredentials.from_json_keyfile_name('./chave.json', scopes)
delegated_credentials = credentials.create_delegated('[email protected]')
http_auth = credentials.authorize(Http())
service = googleapiclient.discovery.build('admin', 'directory_v1',
credentials=delegated_credentials)
response = service.activities().list(users='all',applicationName='chat')
print(response)
I've already used this code for other queries and it's working for accessing the directory and listing users but when I tried to adapt it to query chat activities it doesn't work I have the following error
response = service.activities().list(customerId='all',applicationName='chat')
AttributeError: 'Resource' object has no attribute 'activities'
Solution 1:[1]
You should update your code to use the Reports API and not Admin SDK:
service = googleapiclient.discovery.build('admin', 'reports_v1',
credentials=delegated_credentials)
# customerId is not a valid parameter for Reports API
response = service.activities().list(userKey='all', applicationName='chat')
Moreover, I advise you to give the Quickstart here a try and later you can eventually customize it to your liking.
As for additional resources, you might want to take a look at the following:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ale13 |
