ナンバーズ・リスト
このページでは、所有している Numbers をプログラムでリストアップする方法を紹介します。
自分の Numbers をオンラインで見ることもできます。 開発者ダッシュボード またはコマンドラインから Vonage CLI.
サンプルコードの以下の変数を、独自の値に置き換えてください:
| キー | 説明 |
|---|---|
VONAGE_API_KEY | Your Vonage API key (see it on your dashboard). |
VONAGE_API_SECRET | Your Vonage API secret (also available on your dashboard). |
NUMBER_SEARCH_CRITERIA | The filter criteria. For example, numbers containing |
NUMBER_SEARCH_PATTERN | Where the
|
Write the code
Add the following to list-numbers.sh:
curl "https://rest.nexmo.com/account/numbers?api_key=$VONAGE_API_KEY&api_secret=$VONAGE_API_SECRET&pattern=$NUMBER_SEARCH_CRITERIA&search_pattern=$NUMBER_SEARCH_PATTERN"Run your code
Save this file to your machine and run it:
Prerequisites
npm install @vonage/server-sdkCreate a file named list-numbers.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 list-numbers.js:
const run = async () => {
try {
const filter = {
pattern: NUMBER_SEARCH_CRITERIA,
searchPattern: NUMBER_SEARCH_PATTERN,
};
for await (const number of vonage.number.getOwnedNumbers(filter)) {
console.log(number);
}
} catch (error) {
console.error(error);
}
};
run();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 ListOwnedNumbers 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 ListOwnedNumbers class:
val numbers = client.numbers.listOwned {
pattern(NUMBER_SEARCH_PATTERN, NUMBER_SEARCH_CRITERIA)
}
for (number in numbers) {
println("""
Tel: ${number.msisdn}
Country: ${number.country}
Type: ${number.type}
""".trimIndent()
)
}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.numbers with the package containing ListOwnedNumbers:
Prerequisites
Add the following to build.gradle:
implementation 'com.vonage:server-sdk:9.3.1'Create a class named ListNumbers 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 ListNumbers class:
List<OwnedNumber> response = client.getNumbersClient().listNumbers(
ListNumbersFilter.builder()
.pattern(NUMBER_SEARCH_PATTERN, NUMBER_SEARCH_CRITERIA)
.build()
);
for (OwnedNumber number : response) {
System.out.println("Tel: " + number.getMsisdn());
System.out.println("Type: " + number.getType());
System.out.println("Country: " + number.getCountry());
}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.numbers with the package containing ListNumbers:
Prerequisites
Install-Package VonageCreate a file named ListOwnedNumbers.cs and add the following code:
using Vonage;
using Vonage.Numbers;
using Vonage.Request;Add the following to ListOwnedNumbers.cs:
var credentials = Credentials.FromApiKeyAndSecret(vonageApiKey, vonageApiSecret);Write the code
Add the following to ListOwnedNumbers.cs:
var request = new NumberSearchRequest()
{
SearchPattern = numberSearchPattern,
Pattern = numberSearchCriteria
};
Prerequisites
composer require vonage/clientCreate a file named list-owned.php and add the following code:
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);Write the code
Add the following to list-owned.php:
try {
$filter = new \Vonage\Numbers\Filter\OwnedNumbers();
$filter
->setPattern((int) NUMBER_SEARCH_CRITERIA)
->setSearchPattern((int) NUMBER_SEARCH_PATTERN)
;
$response = $client->numbers()->searchOwned($filter);
echo count($response). " of your numbers match:\n";
foreach($response as $number) {
echo "Tel: " . $number->getMsisdn() . " Type: " . $number->getType() . "\n";
}
} catch (\Exception $e) {
echo $e->getMessage();
}Run your code
Save this file to your machine and run it:
Prerequisites
pip install vonage python-dotenvWrite the code
Add the following to list.py:
from vonage import Auth, Vonage
from vonage_numbers import ListOwnedNumbersFilter
client = Vonage(Auth(api_key=VONAGE_API_KEY, api_secret=VONAGE_API_SECRET))
numbers, count, next = client.numbers.list_owned_numbers(
ListOwnedNumbersFilter(
pattern=NUMBER_SEARCH_CRITERIA, search_pattern=NUMBER_SEARCH_PATTERN
)
)
pprint(numbers)
print(count)
print(next)Run your code
Save this file to your machine and run it:
Prerequisites
gem install vonageCreate a file named list.rb and add the following code:
Run your code
Save this file to your machine and run it: