ユーザー

このコードスニペットでは、Userを取得する方法を学びます。

以下の変数が、便利な方法で必要な値に設定されていることを確認してください:

キー説明
USER_ID

The unique ID of the User.

前提条件

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.

コードを書く

get-user.sh に以下を追加する:

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

全文を見る

コードを実行する

このファイルをあなたのマシンに保存し、実行する:

bash get-user.sh

前提条件

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

get-user.js という名前のファイルを作成し、以下のコードを追加する:

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

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

全文を見る

コードを書く

get-user.js に以下を追加する:

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

全文を見る

コードを実行する

このファイルをあなたのマシンに保存し、実行する:

node get-user.js

前提条件

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.

build.gradle に以下を追加する:

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

GetUser という名前のファイルを作成し、main メソッドに以下のコードを追加する:

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

全文を見る

コードを書く

GetUser ファイルのmain メソッドに以下を追加する:

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

全文を見る

コードを実行する

Gradle用のアプリケーション プラグインを使うことで、アプリケーションの実行を簡単にすることができます。build.gradle を以下のように更新する:

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

以下のgradle コマンドを実行し、com.vonage.quickstart.kt.usersGetUser を含むパッケージに置き換えてアプリケーションを実行する:

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

前提条件

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.

build.gradle に以下を追加する:

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

GetUser という名前のファイルを作成し、main メソッドに以下のコードを追加する:

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

全文を見る

コードを書く

GetUser ファイルのmain メソッドに以下を追加する:

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

全文を見る

コードを実行する

Gradle用のアプリケーション プラグインを使うことで、アプリケーションの実行を簡単にすることができます。build.gradle を以下のように更新する:

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

以下のgradle コマンドを実行し、com.vonage.quickstart.usersGetUser を含むパッケージに置き換えてアプリケーションを実行する:

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

前提条件

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

GetUser.cs という名前のファイルを作成し、以下のコードを追加する:

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

全文を見る

GetUser.cs に以下を追加する:

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

全文を見る

コードを書く

GetUser.cs に以下を追加する:

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

全文を見る

前提条件

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

コードを書く

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)

全文を見る

コードを実行する

このファイルをあなたのマシンに保存し、実行する:

python users/get-user.py

試してみる

コードを実行すると、指定されたUserが表示されます。