如何使用 PHP 库获取可以购买 twilio 号码的国家/地区

How to get countries where twilio numbers are available to buy using PHP library

Twilio 文档提供了一个搜索号码的示例,他们在其中搜索美国本地号码。

$client = new Services_Twilio($sid, $token);
$numbers = $client->account->available_phone_numbers->getList('US', 'Local', array(
    "InRegion" => "AR"
));
foreach($numbers->available_phone_numbers as $number) {
    echo $number->phone_number;
}

有没有办法获取所有可用 twilio 号码的国家/地区?所以我可以在其中一个国家/地区搜索号码。 谢谢

我设法获得了可以使用 twilio 号码的国家/地区列表

public function getAvailableCountries(){

    $client = new \Services_Twilio($this->sid, $this->token);

    $uri = '/'. $client->getVersion() . '/Accounts/' . $this->sid . '/AvailablePhoneNumbers.json';

    try{
        $numbers = $client->retrieveData($uri);

        //returns an array of countries where twilio numbers are supported
        return $numbers->countries;

    }catch(Exception $e){
        return $e->getMessage();
    }
}

List Countries with Voice Service

https://www.twilio.com/docs/api/pricing/voice#list

// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library

use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "AC324da90614bccf7f52759757713463c0";
$token = "your_auth_token";

$client = new Client($sid, $token);

$voiceCountries = $client->pricing->voice->countries->read();

foreach ($voiceCountries as $c) {
    echo $c->isoCountry . PHP_EOL;
}

List Countries with Messaging Service

https://www.twilio.com/docs/api/pricing/messaging#list

// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library

use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "AC324da90614bccf7f52759757713463c0";
$token = "your_auth_token";

$client = new Client($sid, $token);

$messagingCountries = $client->pricing->messaging->countries->stream();

foreach ($messagingCountries as $c) {
    echo $c->isoCountry;
}

List Countries with Twilio Numbers

https://www.twilio.com/docs/api/pricing/phonenumbers#list

// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library

use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "AC324da90614bccf7f52759757713463c0";
$token = "your_auth_token";

$client = new Client($sid, $token);

$phoneNumberCountries = $client->pricing->phoneNumbers->countries->read();

foreach ($phoneNumberCountries as $c) {
    echo $c->isoCountry . PHP_EOL;
}