Mostrar usuarios

En este fragmento de código aprenderá a obtener una lista de Usuarios asociados a una Applications.

Requisitos previos

You will need to use an existing Application containing at least one User in order to see a list of a Users. See the Create Conversation code snippet for information on how to create an Application. See also the Create User code snippet on how to create a User.

Escriba el código

Añada lo siguiente a list-users.sh:

curl "https://api.nexmo.com/v1/users" \
     -H 'Authorization: Bearer '$JWT\
     -H 'Content-Type: application/json'

Ver fuente completa

Ejecute su código

Guarde este archivo en su máquina y ejecútelo:

bash list-users.sh

Requisitos previos

You will need to use an existing Application containing at least one User in order to see a list of a Users. See the Create Conversation code snippet for information on how to create an Application. See also the Create User code snippet on how to create a User.
npm install @vonage/server-sdk

Crea un archivo llamado list-users.js y añade el siguiente código:

const { Vonage } = require('@vonage/server-sdk');

const vonage = new Vonage({
  applicationId: VONAGE_APPLICATION_ID,
  privateKey: VONAGE_PRIVATE_KEY,
});

Ver fuente completa

Escriba el código

Añada lo siguiente a list-users.js:

const run = async () => {
  try{
    for await (const user of vonage.users.listAllUsers()) {
      console.log(user);
    }
  } catch (error) {
    console.error(error);
  }
};

run();

Ver fuente completa

Ejecute su código

Guarde este archivo en su máquina y ejecútelo:

node list-users.js

Requisitos previos

You will need to use an existing Application containing at least one User in order to see a list of a Users. See the Create Conversation code snippet for information on how to create an Application. See also the Create User code snippet on how to create a User.

Añada lo siguiente a build.gradle:

implementation 'com.vonage:server-sdk-kotlin:2.1.1'

Crea un archivo llamado ListUsers y añade el siguiente código al método main:

val client = Vonage {
    applicationId(VONAGE_APPLICATION_ID)
    privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
}

Ver fuente completa

Escriba el código

Añada lo siguiente al método main del archivo ListUsers:

val users = client.users.list()

Ver fuente completa

Ejecute su código

Podemos utilizar el plugin aplicación para Gradle para simplificar la ejecución de nuestra aplicación. Actualiza tu build.gradle con lo siguiente:

apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''

Ejecute el siguiente comando gradle para ejecutar su aplicación, sustituyendo com.vonage.quickstart.kt.users por el paquete que contiene ListUsers:

gradle run -Pmain=com.vonage.quickstart.kt.users.ListUsers

Requisitos previos

You will need to use an existing Application containing at least one User in order to see a list of a Users. See the Create Conversation code snippet for information on how to create an Application. See also the Create User code snippet on how to create a User.

Añada lo siguiente a build.gradle:

implementation 'com.vonage:server-sdk:9.3.1'

Crea un archivo llamado ListUsers y añade el siguiente código al método main:

VonageClient client = VonageClient.builder()
        .apiKey(VONAGE_API_KEY)
        .apiSecret(VONAGE_API_SECRET)
        .build();

Ver fuente completa

Escriba el código

Añada lo siguiente al método main del archivo ListUsers:

List<BaseUser> users = client.getUsersClient().listUsers();

Ver fuente completa

Ejecute su código

Podemos utilizar el plugin aplicación para Gradle para simplificar la ejecución de nuestra aplicación. Actualiza tu build.gradle con lo siguiente:

apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''

Ejecute el siguiente comando gradle para ejecutar su aplicación, sustituyendo com.vonage.quickstart.users por el paquete que contiene ListUsers:

gradle run -Pmain=com.vonage.quickstart.users.ListUsers

Requisitos previos

You will need to use an existing Application containing at least one User in order to see a list of a Users. See the Create Conversation code snippet for information on how to create an Application. See also the Create User code snippet on how to create a User.
Install-Package Vonage

Crea un archivo llamado GetUsers.cs y añade el siguiente código:

using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Vonage;
using Vonage.Request;
using Vonage.Users.GetUsers;

Ver fuente completa

Añada lo siguiente a GetUsers.cs:

var credentials = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
var client = new VonageClient(credentials);

Ver fuente completa

Escriba el código

Añada lo siguiente a GetUsers.cs:

var response = await client.UsersClient.GetUsersAsync(GetUsersRequest.Build().Create());

Ver fuente completa

Requisitos previos

You will need to use an existing Application containing at least one User in order to see a list of a Users. See the Create Conversation code snippet for information on how to create an Application. See also the Create User code snippet on how to create a User.
pip install vonage python-dotenv

Escriba el código

Añada lo siguiente a list-users.py:

from vonage import Auth, Vonage

client = Vonage(
    Auth(
        application_id=VONAGE_APPLICATION_ID,
        private_key=VONAGE_PRIVATE_KEY,
    )
)

users_list, next_page_cursor = client.users.list_users()

print(users_list)

Ver fuente completa

Ejecute su código

Guarde este archivo en su máquina y ejecútelo:

python users/list-users.py

Pruébalo

Al ejecutar el código, obtendrás una lista de usuarios asociados a una Application.