简体   繁体   English

使用twilio验证Java中的电话号码

[英]Validating phone number in Java using twilio

I want to verify if a phone number is valid and what is the type of phone number [cell/landline]. 我想验证电话号码是否有效以及电话号码的类型[小区/固定电话]。 How can this be achieved in Java using twilio? 如何使用twilio在Java中实现这一目标?

Thanks. 谢谢。

Twilio developer evangelist here. Twilio开发者传道者在这里。

For this you can use the Lookup API . 为此,您可以使用Lookup API Take a look through the documentation on how to use the Lookup API in Java . 查看有关如何在Java中使用Lookup API的文档。

Here's a quick example though. 这是一个简单的例子。 You'll need to install the Java helper library , then try this code: 您需要安装Java帮助程序库 ,然后尝试以下代码:

import com.twilio.sdk.LookupsClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.instance.lookups.PhoneNumber;

public class Example {

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "{{ account_sid }}";
  public static final String AUTH_TOKEN = "{{ auth_token }}";

  public static void main(String[] args) throws TwilioRestException {
    LookupsClient client = new LookupsClient(ACCOUNT_SID, AUTH_TOKEN);

    PhoneNumber number = client.getPhoneNumber("+15108675309", true);

    System.out.println(number.getType());
    System.out.println(number.getCarrierName());
  }
}

Let me know if this helps at all. 如果这有帮助,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM