アプリケーション
このコードスニペットでは、指定した Applications の詳細を取得する方法を説明します。
例
以下の置換可能な値が、便利な方法でサンプルコードに設定されていることを確認する必要があります:
| キー | 説明 |
|---|---|
VONAGE_API_KEY | Your Vonage API key (see it on your dashboard). |
VONAGE_API_SECRET | Your Vonage API secret (also available on your dashboard). |
VONAGE_APPLICATION_ID | The Vonage Application ID. |
Write the code
Add the following to get-application.sh:
curl -X "GET" "https://api.nexmo.com/v2/applications/$VONAGE_APPLICATION_ID" \
-H 'Content-Type: application/json' \
-u "$VONAGE_API_KEY:$VONAGE_API_SECRET"Run your code
Save this file to your machine and run it:
Prerequisites
npm install @vonage/server-sdkCreate a file named get-application.js and add the following code:
const { Vonage } = require('@vonage/server-sdk');
const vonage = new Vonage({
apiKey: VONAGE_API_KEY,
apiSecret: VONAGE_API_SECRET,
});Write the code
Add the following to get-application.js:
vonage.applications.getApplication(VONAGE_APPLICATION_ID)
.then((resp) => console.log(resp))
.catch((error) => console.error(error));Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
implementation 'com.vonage:server-sdk-kotlin:2.1.1'Create a class named GetApplication and add the following code to the main method:
val client = Vonage {
apiKey(VONAGE_API_KEY)
apiSecret(VONAGE_API_SECRET)
}Write the code
Add the following to the main method of the GetApplication class:
client.application.application(VONAGE_APPLICATION_ID).get()Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.application with the package containing GetApplication:
Prerequisites
Add the following to build.gradle:
implementation 'com.vonage:server-sdk:9.3.1'Create a class named GetApplication and add the following code to the main method:
VonageClient client = VonageClient.builder()
.apiKey(VONAGE_API_KEY)
.apiSecret(VONAGE_API_SECRET)
.build();Write the code
Add the following to the main method of the GetApplication class:
Application application = client.getApplicationClient().getApplication(VONAGE_APPLICATION_ID);
System.out.println(application.toJson());Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.application with the package containing GetApplication:
Prerequisites
Install-Package VonageCreate a file named GetApplication.cs and add the following code:
using Vonage;
using Vonage.Request;Add the following to GetApplication.cs:
var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SECRET);
var client = new VonageClient(credentials);Write the code
Add the following to GetApplication.cs:
var response = await client.ApplicationClient.GetApplicationAsync(VONAGE_APPLICATION_ID);Prerequisites
composer require vonage/clientCreate a file named get-application.php and add the following code:
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Container($basic));Write the code
Add the following to get-application.php:
try {
$application = $client->applications()->get(VONAGE_APPLICATION_ID);
echo $application->getId() . PHP_EOL;
echo $application->getName() . PHP_EOL;
} catch (\Vonage\Client\Exception\Request $e) {
echo "There was a problem with the request: " . $e->getMessage() . PHP_EOL;
} catch (\Vonage\Client\Exception\Server $e) {
echo "The server encounted an error: " . $e->getMessage() . PHP_EOL;
}Run your code
Save this file to your machine and run it:
Prerequisites
pip install vonage python-dotenvWrite the code
Add the following to get-application.py:
from vonage import Auth, Vonage
from vonage_application import ApplicationData
client = Vonage(Auth(api_key=VONAGE_API_KEY, api_secret=VONAGE_API_SECRET))
response: ApplicationData = client.application.get_application(VONAGE_APPLICATION_ID)
print(response)Run your code
Save this file to your machine and run it:
Prerequisites
gem install vonageCreate a file named get-application.rb and add the following code:
Run your code
Save this file to your machine and run it: