Obtenir un utilisateur

Dans cet extrait de code, vous apprendrez comment obtenir un User.

Exemple

Veillez à ce que les variables suivantes soient réglées sur les valeurs souhaitées en utilisant toute méthode appropriée :

CléDescription
USER_ID

The unique ID of the User.

Conditions préalables

You will need to use an existing Application and have a User in order to be able to get a User. 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 à get-user.sh:

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

Voir la source complète

Exécutez votre code

Enregistrez ce fichier sur votre machine et exécutez-le :

bash get-user.sh

Conditions préalables

You will need to use an existing Application and have a User in order to be able to get a User. 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

Créez un fichier nommé get-user.js et ajoutez le code suivant :

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

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

Voir la source complète

Rédiger le code

Ajouter ce qui suit à get-user.js:

vonage.users.getUser(USER_ID)
  .then((user) => console.log(user))
  .catch((error) => console.error(error));

Voir la source complète

Exécutez votre code

Enregistrez ce fichier sur votre machine et exécutez-le :

node get-user.js

Conditions préalables

You will need to use an existing Application and have a User in order to be able to get a User. 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é GetUser et ajoutez le code suivant à la méthode main:

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

Voir la source complète

Rédiger le code

Ajouter ce qui suit à la méthode main du fichier GetUser:

val user = client.users.user(USER_ID).get()

Voir la source complète

Exécutez votre code

Nous pouvons utiliser le plugin application 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') : ''

Lancez la commande suivante gradle pour exécuter votre application, en remplaçant com.vonage.quickstart.kt.users par le paquet contenant GetUser:

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

Conditions préalables

You will need to use an existing Application and have a User in order to be able to get a User. 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é GetUser et ajoutez le code suivant à la méthode main:

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

Voir la source complète

Rédiger le code

Ajouter ce qui suit à la méthode main du fichier GetUser:

User user = client.getUsersClient().getUser(USER_ID);

Voir la source complète

Exécutez votre code

Nous pouvons utiliser le plugin application 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') : ''

Lancez la commande suivante gradle pour exécuter votre application, en remplaçant com.vonage.quickstart.users par le paquet contenant GetUser:

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

Conditions préalables

You will need to use an existing Application and have a User in order to be able to get a User. 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

Créez un fichier nommé GetUser.cs et ajoutez le code suivant :

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

Voir la source complète

Ajouter ce qui suit à GetUser.cs:

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

Voir la source complète

Rédiger le code

Ajouter ce qui suit à GetUser.cs:

var response = await client.UsersClient.GetUserAsync(GetUserRequest.Parse(USER_ID));

Voir la source complète

Conditions préalables

You will need to use an existing Application and have a User in order to be able to get a User. 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

Rédiger le code

Ajouter ce qui suit à get-user.py:

from vonage import Auth, Vonage
from vonage_users import User

client = Vonage(
    Auth(
        application_id=VONAGE_APPLICATION_ID,
        private_key=VONAGE_PRIVATE_KEY,
    )
)
user: User = client.users.get_user(USER_ID)

print(user)

Voir la source complète

Exécutez votre code

Enregistrez ce fichier sur votre machine et exécutez-le :

python users/get-user.py

Essayez-le

Lorsque vous exécutez le code, vous obtenez l'utilisateur spécifié.