Twilio 有没有办法检索可用电话号码的类型或价格?
假设我只得到了数字和等国家,例如:Twilio 有没有办法检索可用电话号码的类型或价格?,twilio,twilio-api,Twilio,Twilio Api,假设我只得到了数字和等国家,例如: String number = +43720116398; String isoCountry = "AT"; 在购买之前,我试图确定价格或类型。 我想知道这个号码是本地的、移动的还是免费的 遗憾的是,在这种情况下,查找客户端不起作用: public static void main(String[] args) throws TwilioRestException { LookupsClient client = new Loo
String number = +43720116398;
String isoCountry = "AT";
在购买之前,我试图确定价格或类型。
我想知道这个号码是本地的、移动的还是免费的
遗憾的是,在这种情况下,查找客户端不起作用:
public static void main(String[] args) throws TwilioRestException {
LookupsClient client = new LookupsClient(ACCOUNT_SID, AUTH_TOKEN);
PhoneNumber number = client.getPhoneNumber(number , true);
System.out.println(number.getType());
}
它返回不同类型的类型或空值。
如果我能得到同样让我满意的来电号码的类型/价格。
有什么办法吗?在我的例子中,我知道这个号码是本地的还是移动的,所以我只需检查这个本地类型的号码是否存在。如果不是它的移动电话,你可以很容易地添加检查,如果你想检查它是免费的还是移动的。 如果有人能在几天内提供更干净的方法,我会很乐意接受他的回答,否则我会接受我的回答 可运行示例:
public class Main {
private final static String MOBILE = "MOBILE";
private final static String LOCAL = "LOCAL";
private static TwilioRestClient twilioRestClient = new TwilioRestClient("Key", "key");
public static void main(String[] args) {
String number = "+43720116398";
String isoCountry = "AT";
getMsisdnType(number, isoCountry);
}
public static String getMsisdnType(String msisdn, String isoCountry) {
Map<String, String> params = new HashMap<>();
params.put("Contains", msisdn);
Optional<AvailablePhoneNumber> number = twilioRestClient.getAccount().getAvailablePhoneNumbers(params, isoCountry, LOCAL).getPageData().stream().findAny();
if (number.isPresent()) return LOCAL;
return MOBILE;
}
}
公共类主{
私有最终静态字符串MOBILE=“MOBILE”;
私有最终静态字符串LOCAL=“LOCAL”;
私有静态TwilioRestClient TwilioRestClient=新TwilioRestClient(“密钥”、“密钥”);
公共静态void main(字符串[]args){
字符串编号=“+43720116398”;
字符串isoCountry=“AT”;
GetMsisNtype(数字,等国家);
}
公共静态字符串getMsisdnType(字符串msisdn,字符串isoCountry){
Map params=新的HashMap();
参数put(“包含”,msisdn);
可选编号=TwiioRestClient.getAccount().getAvailablePhoneNumbers(参数、等国家、本地)。getPageData().stream().findAny();
if(number.isPresent())返回LOCAL;
返回手机;
}
}