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'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 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-sdkCréez un fichier nommé get-user.js et ajoutez le code suivant :
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 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)
}Rédiger le code
Ajouter ce qui suit à la méthode main du fichier GetUser:
val user = client.users.user(USER_ID).get()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 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();Rédiger le code
Ajouter ce qui suit à la méthode main du fichier GetUser:
User user = client.getUsersClient().getUser(USER_ID);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 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 VonageCréez un fichier nommé GetUser.cs et ajoutez le code suivant :
Ajouter ce qui suit à GetUser.cs:
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-dotenvRé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)Exécutez votre code
Enregistrez ce fichier sur votre machine et exécutez-le :
Essayez-le
Lorsque vous exécutez le code, vous obtenez l'utilisateur spécifié.