Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Muestra la lista de usuarios de dispositivos
En esta página, se explica cómo enumerar los usuarios de dispositivos.
Muestra la lista de usuarios específicos de dispositivos
En los siguientes ejemplos, se muestra cómo enumerar los usuarios específicos de los dispositivos de tu organización.
REST
Para mostrar los usuarios específicos de dispositivos, llama a devices.deviceUsers.list() con el nombre del customer (organización).
HTTP de Python
En el siguiente ejemplo, se muestra cómo mostrar los usuarios específicos de dispositivos mediante la biblioteca HTTP de Python:
"""Sample script to demonstrate the use of the List method in the Devices API."""importjsonimportpprintfromsix.movesimporturllibimportgoogle.auth.transport.requestsfromgoogle.oauth2importservice_accountSCOPES=['https://www.googleapis.com/auth/cloud-identity.devices']BASE_URL='https://cloudidentity.googleapis.com/v1/'# Change this to the location of the service account keySA_FILE=''# Enter the administrator to call as here.ADMIN_EMAIL=''ifnotSA_FILE:print('Please specify the location of the service account key file')ifnotADMIN_EMAIL:print('Please specify the email of the administrator to call as')ifnotSA_FILEornotADMIN_EMAIL:exit(-1)defcreate_delegated_credentials(user_email):credentials=service_account.Credentials.from_service_account_file(SA_FILE,scopes=['https://www.googleapis.com/auth/cloud-identity.devices'])delegated_credentials=credentials.with_subject(user_email)returndelegated_credentials####################################################################### AUTHENTICATE the service account and retrieve an oauth2 access tokenrequest=google.auth.transport.requests.Request()dc=create_delegated_credentials(ADMIN_EMAIL)dc.refresh(request)print('Access token: '+dc.token+'\n')################################ LIST deviceUsers with filter.# Change this filter according to the options here:# https://support.google.com/a/answer/7549103FILTER=urllib.parse.quote_plus('status:approved os:IOS')list_url=BASE_URL+'devices/-/deviceUsers?filter='+FILTERauth_header={'Authorization':'Bearer '+dc.token}content=urllib.request.urlopen(urllib.request.Request(list_url,headers=auth_header)).read()response=json.loads(content)pp=pprint.PrettyPrinter(indent=4)if'deviceUsers'inresponse:print('Listed: '+str(len(response['deviceUsers']))+' deviceUsers\n')forelementinresponse['deviceUsers']:pp.pprint(element)print('Next page token: '+response['nextPageToken'])else:print('Empty response')
Ten en cuenta que FILTER está configurado para filtrar a los usuarios de dispositivos cuyo estado es “aprobado” (status:approved) y el sistema operativo es “IOS” (os:IOS).
Cómo obtener un usuario específico del dispositivo
En los siguientes ejemplos, se muestra cómo recuperar un usuario de dispositivo específico.
REST
Para obtener un usuario de dispositivo específico, llama a devices.deviceUsers.get() con el name del dispositivo y la customer (organización).
HTTP de Python
En el siguiente ejemplo, se muestra cómo recuperar un cliente específico mediante la biblioteca HTTP de Python:
"""Sample script to demonstrate the use of the get method in the Devices API."""importjsonimportpprintfromsix.movesimporturllibimportgoogle.auth.transport.requestsfromgoogle.oauth2importservice_accountSCOPES=['https://www.googleapis.com/auth/cloud-identity.devices']BASE_URL='https://cloudidentity.googleapis.com/v1/'# Change this to the location of the service account keySA_FILE=''# Enter the administrator to call as here.ADMIN_EMAIL=''# Enter the Resource Name. You can get this from the value of the name# field in the results of a List method callRESOURCE_NAME=''ifnotSA_FILE:print('Please specify the location of the service account key file')ifnotADMIN_EMAIL:print('Please specify the email of the administrator to call as')ifnotRESOURCE_NAME:print('Please specify the Resource Name to be retrieved')ifnotSA_FILEornotADMIN_EMAILornotRESOURCE_NAME:exit(-1)defcreate_delegated_credentials(user_email):credentials=service_account.Credentials.from_service_account_file(SA_FILE,scopes=['https://www.googleapis.com/auth/cloud-identity.devices'])delegated_credentials=credentials.with_subject(user_email)returndelegated_credentials####################################################################### AUTHENTICATE the service account and retrieve an oauth2 access tokenrequest=google.auth.transport.requests.Request()dc=create_delegated_credentials(ADMIN_EMAIL)dc.refresh(request)print('Access token: '+dc.token+'\n')################################ Get the resourceget_url=BASE_URL+RESOURCE_NAMEauth_header={'Authorization':'Bearer '+dc.token}content=urllib.request.urlopen(urllib.request.Request(get_url,headers=auth_header)).read()response=json.loads(content)pp=pprint.PrettyPrinter(indent=4)pp.pprint(response)
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-08 (UTC)"],[[["\u003cp\u003eThis document details the process of listing and retrieving device users within an organization.\u003c/p\u003e\n"],["\u003cp\u003eYou can list specific device users by using the REST API call \u003ccode\u003edevices.deviceUsers.list()\u003c/code\u003e, providing the customer's name (organization).\u003c/p\u003e\n"],["\u003cp\u003eThe Python HTTP library example demonstrates how to list device users, including the ability to filter by status and operating system, such as listing only "approved" users on "IOS".\u003c/p\u003e\n"],["\u003cp\u003eRetrieving a specific device user can be done via the REST API call \u003ccode\u003edevices.deviceUsers.get()\u003c/code\u003e, requiring the device's name and the customer's name.\u003c/p\u003e\n"],["\u003cp\u003eThe Python HTTP library example provides a method to get a specific device user, requiring a resource name that can be found within the results of a list method call.\u003c/p\u003e\n"]]],[],null,["# Listing device users\n====================\n\nThis page explains how to list device users.\n\nListing specific device users\n-----------------------------\n\nThe following examples show you how to list specific devices users in your\norganization. \n\n### REST\n\nTo list specific device users, call\n[`devices.deviceUsers.list()`](/identity/docs/reference/rest/v1/devices.deviceUsers/list)\nwith the name of the `customer` (organization).\n\n### Python HTTP\n\nThe following example shows how to list specific device users using the Python\nHTTP library: \n\n \"\"\"Sample script to demonstrate the use of the List method in the Devices API.\"\"\"\n import json\n import pprint\n\n from six.moves import urllib\n\n import google.auth.transport.requests\n from google.oauth2 import service_account\n\n SCOPES = ['https://www.googleapis.com/auth/cloud-identity.devices']\n BASE_URL = 'https://cloudidentity.googleapis.com/v1/'\n\n # Change this to the location of the service account key\n SA_FILE = ''\n\n # Enter the administrator to call as here.\n ADMIN_EMAIL = ''\n\n if not SA_FILE:\n print('Please specify the location of the service account key file')\n if not ADMIN_EMAIL:\n print('Please specify the email of the administrator to call as')\n\n if not SA_FILE or not ADMIN_EMAIL:\n exit(-1)\n\n def create_delegated_credentials(user_email):\n credentials = service_account.Credentials.from_service_account_file(\n SA_FILE,\n scopes=['https://www.googleapis.com/auth/cloud-identity.devices'])\n\n delegated_credentials = credentials.with_subject(user_email)\n\n return delegated_credentials\n\n ######################################################################\n # AUTHENTICATE the service account and retrieve an oauth2 access token\n\n request = google.auth.transport.requests.Request()\n dc = create_delegated_credentials(ADMIN_EMAIL)\n dc.refresh(request)\n print('Access token: ' + dc.token + '\\n')\n\n ###############################\n # LIST deviceUsers with filter.\n\n # Change this filter according to the options here:\n # https://support.google.com/a/answer/7549103\n FILTER = urllib.parse.quote_plus('status:approved os:IOS')\n list_url = BASE_URL + 'devices/-/deviceUsers?filter=' + FILTER\n auth_header = {'Authorization': 'Bearer ' + dc.token}\n content = urllib.request.urlopen(\n urllib.request.Request(list_url, headers=auth_header)).read()\n response = json.loads(content)\n pp = pprint.PrettyPrinter(indent=4)\n\n if 'deviceUsers' in response:\n print('Listed: ' + str(len(response['deviceUsers'])) + ' deviceUsers\\n')\n\n for element in response['deviceUsers']:\n pp.pprint(element)\n print('Next page token: ' + response['nextPageToken'])\n else:\n print('Empty response')\n\nNotice that `FILTER` is set to filter device users to those users whose status\nis \"approved\" (`status:approved`) and operating system is \"IOS\" (`os:IOS`).\n\nGetting a specific device user\n------------------------------\n\nThe following examples show you how to retrieve a specific device user. \n\n### REST\n\nTo get a specific device user, call\n[`devices.deviceUsers.get()`](/identity/docs/reference/rest/v1/devices.deviceUsers/get)\nwith the `name` of the device and the `customer` (organization).\n\n### Python HTTP\n\nThe following example shows how to retrieve a specific customer using the\nPython HTTP library: \n\n \"\"\"Sample script to demonstrate the use of the get method in the Devices API.\"\"\"\n import json\n import pprint\n\n from six.moves import urllib\n\n import google.auth.transport.requests\n from google.oauth2 import service_account\n\n SCOPES = ['https://www.googleapis.com/auth/cloud-identity.devices']\n BASE_URL = 'https://cloudidentity.googleapis.com/v1/'\n\n # Change this to the location of the service account key\n SA_FILE = ''\n\n # Enter the administrator to call as here.\n ADMIN_EMAIL = ''\n\n # Enter the Resource Name. You can get this from the value of the name\n # field in the results of a List method call\n RESOURCE_NAME = ''\n\n if not SA_FILE:\n print('Please specify the location of the service account key file')\n if not ADMIN_EMAIL:\n print('Please specify the email of the administrator to call as')\n if not RESOURCE_NAME:\n print('Please specify the Resource Name to be retrieved')\n\n if not SA_FILE or not ADMIN_EMAIL or not RESOURCE_NAME:\n exit(-1)\n\n def create_delegated_credentials(user_email):\n credentials = service_account.Credentials.from_service_account_file(\n SA_FILE,\n scopes=['https://www.googleapis.com/auth/cloud-identity.devices'])\n\n delegated_credentials = credentials.with_subject(user_email)\n\n return delegated_credentials\n\n ######################################################################\n # AUTHENTICATE the service account and retrieve an oauth2 access token\n\n request = google.auth.transport.requests.Request()\n dc = create_delegated_credentials(ADMIN_EMAIL)\n dc.refresh(request)\n print('Access token: ' + dc.token + '\\n')\n\n ###############################\n # Get the resource\n get_url = BASE_URL + RESOURCE_NAME\n auth_header = {'Authorization': 'Bearer ' + dc.token}\n content = urllib.request.urlopen(\n urllib.request.Request(get_url, headers=auth_header)).read()\n response = json.loads(content)\n pp = pprint.PrettyPrinter(indent=4)\n pp.pprint(response)"]]