Liste des utilisateurs
Dans cet extrait de code, vous apprendrez à obtenir la liste des utilisateurs associés à une Applications.
Conditions préalables
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.
Rédiger le code
Ajouter ce qui suit à list-users.sh:
curl "https://api.nexmo.com/v1/users" \
-H 'Authorization: Bearer '$JWT\
-H 'Content-Type: application/json'Exécutez votre code
Enregistrez ce fichier sur votre machine et exécutez-le :
Conditions préalables
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-sdkCréez un fichier nommé list-users.js et ajoutez le code suivant :
const { Vonage } = require('@vonage/server-sdk');
const vonage = new Vonage({
applicationId: VONAGE_APPLICATION_ID,
privateKey: VONAGE_PRIVATE_KEY,
});Rédiger le code
Ajouter ce qui suit à list-users.js:
const run = async () => {
try{
for await (const user of vonage.users.listAllUsers()) {
console.log(user);
}
} catch (error) {
console.error(error);
}
};
run();Exécutez votre code
Enregistrez ce fichier sur votre machine et exécutez-le :
Conditions préalables
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.
Ajouter ce qui suit à build.gradle:
implementation 'com.vonage:server-sdk-kotlin:2.1.1'Créez un fichier nommé ListUsers et ajoutez le code suivant à la méthode main:
val client = Vonage {
applicationId(VONAGE_APPLICATION_ID)
privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
}Rédiger le code
Ajouter ce qui suit à la méthode main du fichier ListUsers:
val users = client.users.list()Exécutez votre code
Nous pouvons utiliser le plugin Applications pour Gradle afin de simplifier l'exécution de notre application. Mettez à jour votre build.gradle avec ce qui suit :
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Exécutez la commande gradle suivante pour exécuter votre application, en remplaçant com.vonage.quickstart.kt.users par le paquet contenant ListUsers:
Conditions préalables
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.
Ajouter ce qui suit à build.gradle:
implementation 'com.vonage:server-sdk:9.3.1'Créez un fichier nommé ListUsers et ajoutez le code suivant à la méthode main:
VonageClient client = VonageClient.builder()
.apiKey(VONAGE_API_KEY)
.apiSecret(VONAGE_API_SECRET)
.build();Rédiger le code
Ajouter ce qui suit à la méthode main du fichier ListUsers:
List<BaseUser> users = client.getUsersClient().listUsers();Exécutez votre code
Nous pouvons utiliser le plugin Applications pour Gradle afin de simplifier l'exécution de notre application. Mettez à jour votre build.gradle avec ce qui suit :
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Exécutez la commande gradle suivante pour exécuter votre application, en remplaçant com.vonage.quickstart.users par le paquet contenant ListUsers:
Conditions préalables
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 VonageCréez un fichier nommé GetUsers.cs et ajoutez le code suivant :
using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Vonage;
using Vonage.Request;
using Vonage.Users.GetUsers;Ajouter ce qui suit à GetUsers.cs:
var credentials = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
var client = new VonageClient(credentials);Rédiger le code
Ajouter ce qui suit à GetUsers.cs:
var response = await client.UsersClient.GetUsersAsync(GetUsersRequest.Build().Create());Conditions préalables
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-dotenvRédiger le code
Ajouter ce qui suit à 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)Exécutez votre code
Enregistrez ce fichier sur votre machine et exécutez-le :
Essayez-le
Lorsque vous exécutez le code, vous obtenez une liste des utilisateurs associés à une Applications.