ユーザーの作成
このコード・スニペットでは、ユーザを作成する方法を学びます。
例
以下の変数が、便利な方法で必要な値に設定されていることを確認してください:
| キー | 説明 |
|---|---|
USER_NAME | The unique name of the User. |
USER_DISPLAY_NAME | The display name of the User. |
Prerequisites
You will need to use an existing Application in order to be able to create a User. See the Create Conversation code snippet for information on how to create an Application.
Run your code
Save this file to your machine and run it:
Prerequisites
You will need to use an existing Application in order to be able to create a User. See the Create Conversation code snippet for information on how to create an Application.
Create a file named create-user.js and add the following code:
const { Vonage } = require('@vonage/server-sdk');
const vonage = new Vonage({
applicationId: VONAGE_APPLICATION_ID,
privateKey: VONAGE_PRIVATE_KEY,
});Write the code
Add the following to create-user.js:
vonage.users.createUser({
'name': USER_NAME,
'displayName': USER_DISPLAY_NAME,
})
.then((user) => console.log(user))
.catch((error) => console.error(error));Run your code
Save this file to your machine and run it:
Prerequisites
You will need to use an existing Application in order to be able to create a User. See the Create Conversation code snippet for information on how to create an Application.
Add the following to build.gradle:
Create a class named CreateUser and add the following code to the main method:
Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.users with the package containing CreateUser:
Prerequisites
You will need to use an existing Application in order to be able to create a User. See the Create Conversation code snippet for information on how to create an Application.
Add the following to build.gradle:
Create a class named CreateUser and add the following code to the main method:
Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.users with the package containing CreateUser:
Prerequisites
You will need to use an existing Application in order to be able to create a User. See the Create Conversation code snippet for information on how to create an Application.
Create a file named CreateUser.cs and add the following code:
Add the following to CreateUser.cs:
Prerequisites
You will need to use an existing Application in order to be able to create a User. See the Create Conversation code snippet for information on how to create an Application.
Run your code
Save this file to your machine and run it:
試してみる
コードを実行すると、新しいユーザが作成されます。