認証コードを送信する
ユーザーの電話番号を収集したら、認証プロセスを開始します。 Verifyリクエスト をVerify APIに追加します。
を返します。 request_id.を作成するときなど、その後の API 呼び出しで特定の検証リクエストを識別するために使用します。 チェックリクエスト で、ユーザーが正しいコードを入力したかどうかを確認する。
サンプルコードの以下の変数を、独自の値に置き換えてください:
| キー | 説明 |
|---|---|
VONAGE_API_KEY | Your Vonage API key (see it on your dashboard). |
VONAGE_API_SECRET | Your Vonage API secret (also available on your dashboard). |
RECIPIENT_NUMBER | The phone number to verify |
BRAND_NAME | Included in the message to explain who is confirming the phone number |
Write the code
Add the following to send-verification-code.sh:
curl GET "https://api.nexmo.com/verify/json?api_key=$VONAGE_API_KEY&api_secret=$VONAGE_API_SECRET&number=$VERIFY_NUMBER&brand=AcmeInc"Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
Create a class named StartVerification 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.verify.legacy with the package containing StartVerification:
Prerequisites
Add the following to build.gradle:
Create a class named StartVerification 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 StartVerification class:
VerifyResponse response = client.getVerifyClient().verify(VERIFY_NUMBER, VERIFY_BRAND_NAME);
if (response.getStatus() == VerifyStatus.OK) {
System.out.printf("RequestID: %s", response.getRequestId());
}
else {
System.out.printf("ERROR! %s: %s", response.getStatus(), response.getErrorText());
}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.verify with the package containing StartVerification:
Prerequisites
Install-Package VonageCreate a file named SendVerificationRequest.cs and add the following code:
Add the following to SendVerificationRequest.cs:
Prerequisites
composer require vonage/clientCreate a file named request.php and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
pip install vonage python-dotenvRun your code
Save this file to your machine and run it:
Prerequisites
gem install vonageCreate a file named request.rb and add the following code:
Write the code
Add the following to request.rb:
response = client.verify.request(
number: VERIFY_NUMBER,
brand: VERIFY_BRAND_NAME
)Run your code
Save this file to your machine and run it:
注:エラーコード15が表示された場合: The destination number is not in a supported network対象ネットワークがプラットフォームの不正防止システムによってブロックされている可能性があります。参照 ベロシティ・ルール.