Twilio available phone search by prefix

↘锁芯ラ 提交于 2019-12-11 19:16:02

问题


How do I search for phone number by prefix using the API? The Twilio "Buy A Number" tool lets you search for begins with term, but I don't see a way to do it using the API.

You can do:

AvailablePhoneNumbers/US/Local?Contains=703%

But that still finds numbers with 703 anywhere, not just the prefix. Only way I can see to do this is using the * single number search, a la:

AvailablePhoneNumbers/US/Local?Contains=703*******

But then how do I make that generic to any country? Have a lookup table of phone number lengths for every country so I can add the appropriate number of *'s?


回答1:


Twilio provides this information in their API docs (Find phone numbers by number pattern).

For example using PHP:

<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACde6f132a3c49700934481addd5ce1659"; 
$token = "{{ auth_token }}"; 
$client = new Services_Twilio($sid, $token);

$numbers = $client->account->available_phone_numbers->getList('US', 'Local', array(
        "Contains" => "510555****"
    ));
foreach($numbers->available_phone_numbers as $number) {
    echo $number->phone_number;
}


来源:https://stackoverflow.com/questions/37055441/twilio-available-phone-search-by-prefix

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!